MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的问题

来源:互联网 发布:小世界网络的度分布 编辑:程序博客网 时间:2024/06/05 02:28

问题描述:
从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xxx.xxx.xxx.85’(111)错误。
[mysql@vvmvcs0 ~]mysqlhxxx.xxx.xxx.85urootpEnterpassword:www.2cto.comERROR2003(HY000):CantconnecttoMySQLserveronxxx.xxx.xxx.85(111)[mysql@vvmvcs0 ] perror 111
OS error code 111: Connection refused
查看errorCode
[mysql@vvmvcs0 ~]perror111OSerrorcode111:Connectionrefused1pingxxx.xxx.xxx.85ping[mysql@vvmvcs0 ] ping xxx.xxx.xxx.85
PING xxx.xxx.xxx.85 (xxx.xxx.xxx.85) 56(84) bytes of data.
64 bytes from xxx.xxx.xxx.85: icmp_seq=1 ttl=63 time=0.230 ms
2,排查可能由于85上my.cnf里配置了skip_networking或者bind_address,只允许本地socket连接
2.1 在[mysqld]下设置skip_networking,
知识说明: 这使用MySQL只能通过本机Socket连接(socket连接也是本地连接的默认方式),放弃对TCP/IP的监听 www.2cto.com
当然也不让本地java程序连接MySQL(Connector/J只能通过TCP/IP来连接)。
2.2 可能使用了bind_address=127.0.0.1(当然也可以是其他ip)
[mysqld]
bind_address=127.0.0.1
知识说明:这种情况可以TCP/IP连接
通过查看了my.cnf文件,以上两个都是没设置的,排除掉这两种情况
3,排查DNS解析问题,检查是否设置了: skip_name_resolve。 这个情况肯定不可能,因为我用的是ip,不是主机名。
[mysqld]
skip_name_resolve
知识说明:这个参数加上后,不支持主机名的连接方式。
4, 排查用户和密码问题, 其实用户和密码的错误,不会出现111的,所以排除用户密码问题
ERROR 1045 (28000): Access denied for user ‘root’@’XXXX’ (using password: YES)
5,排查–port问题,有可能85的MySQL port不是默认3306, 这样我远程连接时,没有指定–port,用的是3306, 而85上没有对3306进行监听。
ps -ef | grep mysqld
果然是: 85上的MySQL使用的是3308 port.
最终连接方式:加上–port=3308
[mysql@vvmvcs0 ~]mysqlhxxx.xxx.xxx.85urootpport=3308Enterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.85MySQL,mysqlurootportMySQLport33061.MySQLmysqlprotocol=tcp,socketwww.2cto.com2,MySQLsocketsokectportS(socket=namesocketport85port3308MySQL3306socketportbash3.2 mysql -uroot –port=3308
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql -uroot –port=3306
Welcome to the MySQL monitor. Commands end with ; or \g.
再次说明基础细节很重要啊。

0 0
原创粉丝点击