远程连接服务器的mysql出现2003-Cant connect to MySQL server

问题

我在用自己的windows上的navicat远程连接ubuntu服务器的mysql,提示2003错误,无法连接,搜索博客,经过以下步骤解决。

注:本人mysql为5.7

解决步骤

  1. 查看服务器防火墙状态,3306端口是否开放,结果发现我的服务器没有防火墙
firewall-cmd --state
  1. 查看mysql是否允许远程连接
mysql -uroot -p
use mysql;
select host,user,authentication_string from mysql.user;

远程连接服务器的mysql出现2003-Cant connect to MySQL server

如果没有host为%的用户,代表不允许远程连接。

那么输入以下命令

grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';
flush privileges;

远程连接服务器的mysql出现2003-Cant connect to MySQL server

其中xxxxxx是你的mysql密码。一定要flush一下

  1. 修改配置文件
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

远程连接服务器的mysql出现2003-Cant connect to MySQL server

将bind-address = 127.0.0.1改为0.0.0.0

  1. 重启mysql
sudo service mysql restart
上一篇:PHP M题3基础题示例Z


下一篇:如何在 EXCEL 2003 插入的方框内打对勾,复选框