Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060 "Unknown error")

Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
第一步:
首先检查mysql配置文件里面是否设置了默认连接地址,默认端口号

bind-address = 0.0.0.0
port=3306

然后发现并没有
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060

第二步:
输入密码进入mysql数据库

mysql -u root -p

设置主机权限,并设置连接密码(注意%为允许任何远程连接,工作时慎用):

//允许root从任何主机连接到mysql服务器,并使用你设置的密码连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '设置你的连接数据库密码' WITH GRANT OPTION;
//立即执行授权命令
flush privileges;

查看授权用户:

SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
之后再次测试连接,发现依旧连不上

第三步:
去服务器检查端口号,发现并没有配置3306端口号,既然没有,那就加上看看!
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
最后在去测试连接发现立即连接成功!
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060
Linux系统下远程连接mysql出错-2003 -Can't connect to MySQL server on 'ip' (10060

你可能感兴趣的:(MySQL数据库,虚拟机,服务器)