ERROR 2002 (HY000): Can't connect to local MySQL Server through socket '/var/lib/mysql/MySQL.sock' (2)
解決方法:
1)默認的MySQL.sock文件是在/tmp目錄下。
2)我們建立一個軟連接,ln -s /tmp/mysql.sock /var/lib/mysql/MySQL.sock
問題2:Timeout error occurred trying to start MySQL Daemon.
#/etc/init.d/MySQLd restart
stopping MySQL [ok]
Timeout error occurred trying to start MySQL Daemon. [failure]
但是這個時候mysql實際上已經起動了,因為用netstat -ln命令去看3306端口已經起動.使用MySQL -u root -p passWord也能連接到數據庫.
解決方法:
修改/etc/init.d/MySQLd.
在mysql裡創建dameon用戶,然後再修改/etc/init.d/MySQLd.
具體操作如下:
我們不妨先看看/etc/init.d/MySQLd起動腳本是如何工作的,注意下面的一段
# If you've removed anonymous users, this line must be changed to
# use a user that is allowed to ping MySQLd.
ping="/usr/bin/mysqladmin -uUNKNOWN_MySQL_USER ping"
# Spin for a maximum of ten seconds waiting for the server to come up
if [ $ret -eq 0 ]; then
for x in 1 2 3 4 5 6 7 8 9 10; do
if [ -n "`$ping 2> /dev/null`" ]; then
break;
else
sleep 1;
fi
done
if !([ -n "`$ping 2> /dev/null`" ]); then
echo "Timeout error occurred trying to start MySQL
Daemon." action $"Starting $prog: " /bin/false
else
action $"Starting $prog: " /bin/true
fi
else
action $"Starting $prog: " /bin/false
fi
[ $ret -eq 0 ] && touch /var/lock/subsys/MySQLd
return $ret
我們看到,腳本判斷mysql是否起動,使用的是MySQLadmin ping命令.
而這個命令想要正確執行是需要能夠登錄mysql的.現在一些默認帳號已經刪除,而且其它帳號已經設置了密碼(默認沒有設置密碼).於是它沒有辦法連接到MySQL.
於是我用了下面的辦法解決.
a)建立一個帳號,不設置密碼,不給任何權限.
b)修改/etc/init.d/MySQLd
下面我給出具體操作
#MySQL -u root -p passwd
MySQL>GRANT select ON test.* TO daemon@localhost
MySQL>revoke select on test.* from daemon@localhost
vi打開/etc/init.d/MySQLd
把下面這行
ping="/usr/bin/mysqladmin -uUNKNOWN_MySQL_USER ping"
修改為
ping="/usr/bin/MySQLadmin -udaemon ping"
保存,退出.
重新起動MySQL
#/etc/init.d/MySQLd restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
這樣就可以了.