远程连接服务器的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;

image-20210629174924087

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

那么输入以下命令

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

image-20210629175216994

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

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

image-20210629175244146

将bind-address = 127.0.0.1改为0.0.0.0

  1. 重启mysql
sudo service mysql restart
posted @ 2021-06-29 18:53  曾凡璐  阅读(1693)  评论(0)    收藏  举报