Mac Navicat连接MySQL8.0.11出错:2003 - Can't connect to MySQL server on ……(61 "Connection refused")

MySQL8.0.11处于空密码情况下,Navicat for MySQL连接MySQL会出现以下提示:

2003 - Can't connect to MySQL server on '127.0.0.1' (61 "Connection refused")

1、停止mysql,也可在苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server)

sudo /usr/local/mysql/support-files/mysql.server stop

2、设置mysql密码,如若忘记密码,可通过下边(第5步)命令重置密码

ALTER user 'root'@'localhost' IDENTIFIED BY '123456'

3、打开Navicat重新连接mysql,输入mysql密码,ok!

Mac Navicat连接MySQL8.0.11出错:2003 - Can't connect to MySQL server on ……(61 "Connection refused")

4、终端启停mysql:

启动MySQL服务: sudo /usr/local/MySQL/support-files/mysql.server start

停止MySQL服务: sudo /usr/local/mysql/support-files/mysql.server stop

重启MySQL服务: sudo /usr/local/mysql/support-files/mysql.server restart

5、重置MySQL密码:

进入终端输入:

cd /usr/local/mysql/bin/

登录管理员权限,提示输入管理员密码:

sudo su

回车后输入以下命令来禁止mysql验证功能,回车后mysql会自动重启(偏好设置中mysql的状态会变成running)

./mysqld_safe --skip-grant-tables &

./mysql

FLUSH PRIVILEGES;

此处需注意:因为现在是新版本8.0了 ,老版本的修改密码的语法已不再适用,mysql 5.7.9以后废弃了password字段和password()函数;

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD('123456')' at line 1

mysql>ALTER user 'root'@'localhost' IDENTIFIED BY '123456' 

密码重置成功,重启mysql即可;

如有其他问题可参考官方文档:

https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html