LoginSignup
2
3

More than 5 years have passed since last update.

MySQL5.7のtemporary password文字列を拾うワンライナー

Last updated at Posted at 2016-03-19

5.7からパッケージを入れた直後のrootのパスワードになるやつです。スクリプトから使いたい時にでもご利用ください。

$ sudo grep 'temporary password' /var/log/mysqld.log | sed -e "s/.*root@localhost: //"
5UGYEVdG)_g,

$ mysql -u root -p'5UGYEVdG)_g,'
mysql>

mysqlコマンドから流す場合は--connect-expired-passwordをつけないと失敗するっぽいので、以下の様な感じにするといいかも。

password_update.sh
TEMP_PASS=`sudo grep 'temporary password' /var/log/mysqld.log | sed -e "s/.*root@localhost: //"`
UPDATE_SQL="SET PASSWORD FOR root@localhost=PASSWORD('newpassword');"

mysql -u root -p"${TEMP_PASS}" -e "${UPDATE_SQL}" --connect-expired-password

しかし毎回毎回、見事に記号入れてくれるのが地味にイラッときます…(エスケープがだるい)

2
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
2
3