ローカルのmysqlつなごうとしたら、rootのパスワード設定したのにパスワードを忘れた。
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.11 Homebrew
- mysqlを停止
mysql.server stop
- safeモードで起動
mysqld_safe --skip-grant-tables
- 新パスワードを設定
update user set authentication_string=password('新パスワード') where user='root';
- 反映
FLUSH PRIVILEGES;
- 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'.