MAC下安装mysql,连接报错Access denied for user ‘root’@‘localhost’ (using password: YES)
解决方法:
第一步:苹果->系统偏好设置->MySQL,关闭mysql服务
第二步:
进入终端
输入(cd /usr/local/mysql/bin/)回车
kakakakakaoooo:~ mac$ cd /usr/local/mysql/bin/
输入(sudo su)回车以获取管理员权限
kakakakakaoooo:bin mac$ sudo su
输入开机密码
输入(./mysqld_safe --skip-grant-tables &)回车以禁止mysql验证功能,mysql会自动重启,偏好设置中的mysql状态会变成running
sh-3.2# ./mysqld_safe --skip-grant-tables &
第三步:
新建一个终端窗口(cmd+T),
输入命令(./mysql)回车
kakakakakaoooo:bin mac$ ./mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
输入命令(flush privileges;)分号别忘记输了
mysql> flush privileges
;
输入命令(set password for ‘root’@‘localhost’ = password(‘root’);) password(‘root’)中的root为新密码,自己随便设置,分号别忘记输入
至此,密码修改成功,可以正常登入了。