首页 > 代码库 > 升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

系统升级到macOS 10.12后启动mysql后,在终端输入mysql 报错
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES/NO)

解决办法
1 在系统偏好设置里关闭mySQL
2 $ cd /usr/bin
3 $ sudo mysqld_safe --skip-grant-tables
4 再打开一个终端
$ mysql
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD(‘123456‘) WHERE user = ‘root‘;
UPDATE mysql.user SET Password=PASSWORD(‘123456‘) WHERE User=‘root‘;
如果你的MySQL 版本大于5.7(可在终端输入命令:mysql --version 查看mysql的版本号)
输入这个命令:
UPDATE mysql.user SET authentication_string=PASSWORD(‘123456‘) WHERE User=‘root‘;
最后 mysql> exit;

在系统偏好设置里启动mysql即可。

参考文档:

http://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045

http://stackoverflow.com/questions/489119/mysql-error-1045-access-denied?rq=1

升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)