LoginSignup
4
3

More than 5 years have passed since last update.

mysqlのパスワードにビックリマーク!入れたらいろいろハマった話

Posted at

この記事について

開発環境つくるのにmysqlのパスワードなんて適当なもので良いのだが、特殊文字を含んだパスワードしか使えない制約入れて、実際にビックリマーク含むパスワードにしてたらハマった :cry: 結局ビックリマークやめて他の特殊文字を使うようにして回避した話。

結論

  • パスワードにビックリマークはやめよう
  • URLエスケープしやすい文字が良いっぽい

現象

↓の感じでsequelでマイグレーションさせようとしたら

$ bundle exec sequel -m migrations "mysql2://user_name:password!@127.0.0.1/db_name"
-bash: !@127.0.0.1: event not found

みたいになる。なんで?と思ったらビックリマークはbashシェルで特殊扱いされる奴だったとか。

回避方法

mysqlのパスワードをビックリマークじゃなくてシャープに変更

mysql> set password for 'user_name'@'localhost' = PASSWORD('password#');

#%23 にエスケープして実行

$ bundle exec sequel -m migrations "mysql2://user_name:password%23@127.0.0.1/db_name"

原因

bashシェルでビックリマークの使い方

一つ前のコマンドを再度実行する

!!

コマンドの履歴の1番を実行する

!1

クォーテーションの中も優先的に置き換えちゃう

直接的な原因は↓みたいな動作になることだったから

$ ls -al
$ echo "!!"
echo "ls -al"
ls -al

参考

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3