Swift51.com
麦子学院 头像
麦子学院  2017-02-12 18:47

远程连接MySQL数据库问题总结

回复:0  查看:4050  

远程连接MySQL数据库时,陆陆续续遇到了一些杂七杂八的问题,相信很多人也曾经遇到过这类问题,下面总结归纳在下面,方便以后直接查找。

  1:出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)

  [root@cluster-00 ~]# mysql -h 10.20.34.76 -u root -p

  Enter password:

  ERROR 2003 (HY000): Can't connect to MySQL server on '10.20.34.76' (111)

  [root@cluster-00 ~]# perror 111

  OS error code 111: Connection refused

  [root@cluster-00 ~]#

远程连接MySQL数据库问题总结

原因1: 服务器10.20.34.76不能访问或ping.这个很好验证。

  原因2MySQL服务没有启动。这个验证也非常方便。

  原因3MySQL配置了参数skip-networking,注销该参数即可

  2: ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (113)

  [root@cluster-00 ~]# mysql -h 10.20.34.76 -uroot -p

  Enter password:

  ERROR 2003 (HY000): Can't connect to MySQL server on '10.20.34.76' (113)

  [root@cluster-00 ~]# perror 113

  OS error code 113: No route to host

远程连接MySQL数据库问题总结

关闭防火墙(不推荐)或是开放相关端口(默认为3306)后,问题即可解决。

  3ERROR 1045 (28000): Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES)

  [root@cluster-00 ~]# mysql -h 10.20.34.76 -uroot -p

  Enter password:

  ERROR 1045 (28000): Access denied for user 'root'@'192.168.9.224' (using password: YES)

  [root@cluster-00 ~]#

  原因:root账户权限不够,可能仅仅只用于本地,不能远程登录。需要设置账号权限。注意:这里仅仅是测试图方便,正常情况是不应该开放root的远程访问权限的。出于安全因素考虑,一般应该关闭远程访问。

 

来源:潇湘隐者