mysqlのパスワード忘れた #mysql

ローカルのmysqlつなごうとしたら、rootのパスワード設定したのにパスワードを忘れた。

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.11 Homebrew
  1. mysqlを停止
    mysql.server stop
  2. safeモードで起動
    mysqld_safe --skip-grant-tables
  3. 新パスワードを設定
    update user set authentication_string=password('新パスワード') where user='root';
  4. 反映
    FLUSH PRIVILEGES;
  5. mysqlを再起動
    mysql.server restart
補足

MySQL5.7はuserテーブルからpasswordフィールドが削除されたので、authentication_stringを使う必要があるらしい。

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

http://stackoverflow.com/questions/30692812/mysql-user-db-does-not-have-password-columns-installing-mysql-on-osx