一个无法访问mysql的错误: ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (111)

来源:互联网 发布:天刀本地网络异常 编辑:程序博客网 时间:2024/05/16 06:22

今天遇到一个MySQL client连接的错误,耽误了不少时间。到最后才发现还是因为基本功不扎实。

 

[root@XXXX tmp]# mysql -uroot -ppass -h x.x.x.x
ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (111)
[root@XXXX tmp]# perror 111
OS error code 111:  Connection refused
[root@XXXX tmp]#

在网上猛找了一把,有几个比较接近的case,都说是检查skip-network, bind-address这些设置。

 

其实是因为我的MySQL server用的不是默认端口3306,而我在命令行中,并没有给出这个新的端口号。

 

[root@XXXX ~]# mysql -uroot -ppass -h x.x.x.x -P3333
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 59
Server version: 5.1.45-community-log MySQL Community Server (GPL)

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

mysql>
mysql> exit
Bye
[root@XXXX ~]#

 

连接正常。