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> /program/null`" ]; then
break;
else
sleep 1;
fi
done
if !([ -n "`$ping 2> /program/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 ]
這樣就可以了.