問題1:登錄mysql的錯誤
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 ]
這樣就可以了.