Mac 版本10.11
mysql 版本 5.7
1. 首先 从 偏好设置-mysql 停止mysql服务器 运行
2. 然后新建一个终端中,打开 mysql/bin 所在位置, 本机为:
cd /usr/local/mysql/bin
3. 运行一个deamon进程,使能够跳过权限检查:
sudo ./mysqld_safe --skip-grant-tables
4. 另新建一个终端并输入如下命令,更新用户root的密码:
注意以上命令红色字段,如果是mysql v5.6及以前版本,则字段名为 password,$ mysql mysql> use mysql; mysql> UPDATE user SET password=PASSWORD('YOUR_NEW_PASSWORD_HERE') WHERE user = 'root'; mysql> exit;
如果是mysql v5.7,table里面并没有password此字段,会得到错误提示:
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
在v5.7中,password字段名为:authentication_string,则应输入:
update user set authentication_string=password('1111') where user='root';
5. kill刚才的deamon进程,并且 在偏好设置-mysql中开启mysql服务
6. 在终端中输入: mysql -u root -p 即可解决问题。
Ref: 1. http://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045
2. http://stackoverflow.com/questions/30692812/mysql-user-db-does-not-have-password-columns-installing-mysql-on-osx/31122246#31122246