標籤:
裝了個navicat ,然後去串連mysql伺服器,一直連不上,一開始以為是防火牆問題,後來防火牆都關閉,
iptable服務關閉,還是不行,網上查了下:主要是因為設定了bind_address=127.0.0.1
原文引用:
問題描述:
從一台linux遠端連線另一台linux上的MySQL, 出現ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘xxx.xxx.xxx.85‘(111)錯誤。[mysql@vvmvcs0 ~]$ mysql -hxxx.xxx.xxx.85 -uroot -pEnter password: www.2cto.comERROR 2003 (HY000): Can‘t connect to MySQL server on ‘xxx.xxx.xxx.85‘ (111)[[email protected] ~]$
perror 111OS error code 111: Connection refused查看errorCode[[email protected] ~]$ perror 111OS error code 111: Connection refused問題分析:1,可能網路連接問,遠程ping xxx.xxx.xxx.85 ,能ping通,排除此情況[[email protected] ~]$ ping xxx.xxx.xxx.85PING 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 ms2,排查可能由於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[[email protected] ~]$ mysql -hxxx.xxx.xxx.85 -uroot -p --port=3308Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.為什麼出現這麼低級的錯誤呢?因為我一直在用85上的MySQL, 而且每次都是直接用mysql -uroot就串連上了,沒有指定--port,這樣我就一直以為這MySQL的port一直是預設的3306的。其實根本原因是:1. MySQL本地串連,如果不指mysql --protocol=tcp, 串連預設是socket方式串連的。這點大家都知道。2. MySQL socket串連是根據sokect檔案來的,與--port不相關的,如果是一機多執行個體,則用-S(或者--socket=name )來指定串連哪個執行個體。就是這個
socket串連對--port無識別效果,導致排查這個問題這麼久。見下面: 其實85上只有一個port為3308的MySQL執行個體,但是用3306仍然是串連上此執行個體,說明socket串連方式忽略--port參數。-bash-3.2$ mysql -uroot --port=3308Welcome to the MySQL monitor. Commands end with ; or \g.mysql -uroot --port=3306Welcome to the MySQL monitor. Commands end with ; or \g.再次說明
基礎細節很重要啊。 轉自:http://blog.csdn.net/qustdjx/article/details/26937325
[轉]MySQL遠端連線ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的問題