By MBPDLPayday Loans

MySQL 无法连接

其实去年帮Frank Ye搭Moodle的时候曾经遇到过这个问题, 当时匆匆忙忙解决掉就没做记录. 幸亏当时在drl上发帖问的, 在回帖里我写了点原因. 这使得昨天修复这个问题的时候少走了弯路.

当服务器IP修改过后, 我们往往只会把network下面的配置改掉, 忽略掉mysql的配置文件. 而事实上, 如果是本机连接的话, 倘若在修改后没有重启机器, mysql的配置文件修改与否并不直接产生作用. 但是从别的机器已经无法telnet到该mysql的3306端口了. 这个时候去重启mysql就会报错, 说找不到socket. 第一次我解决的时候从这个错误信息着手, 想恢复mysql.sock文件…

原因定位到以后就很好办了, 直接vim /etc/mysql/my.conf文件,修改ip bind. 然后/etc/init.d/mysql restart 搞定.

[附]错误信息:

error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
Killing MySQL database server by signal: mysqld.
Starting MySQL database server: mysqld…failed.
Please take a look at the syslog.
/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!

Leave a Reply