最近在linux上面用django寫一個小網站 ,數據庫用的是mysql,但是突然有一天,出現了奇怪的問題,報錯: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 然後我去看這個文件'/var/lib/mysql/mysql.sock' ,但是沒有找到,我就有點不明白了,然後想起可能是mysql的服務mysqld沒有啓動,因爲mysql -u root -p這個命令還是能用的,所以趕緊查看了一下service mysqld status 是什麼狀態,纔看到原來沒有啓動,然後就沒有問題了。
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@localhost ~]# /etc/init.d/mysqld start ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) shell> chown -R mysql:mysql /var/lib/mysql 接着啓動服務器 shell> /etc/init.d/mysql start 服務器正常啓動後察看 /var/lib/mysql 自動生成mysql.sock文件。 但是我的問題仍然沒有得到解決。
[mysql.server] If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as: [client] 發現依舊如此,運行/etc/init.d/mysql start報錯:Starting MySQLCouldn't find MySQL manager or server 問題解決。
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) in /home/httpd/html/show.php on line 9 請將 /tmp/mysql.sock link 到 /var/lib/mysql 目錄裏即可: linux# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Ununtu 15.04安裝MySql(Django連接Mysql):http://www.linuxdiyf.com/linux/13783.html |
MySQL報錯的解決'Can't connect to local MySQL server through socket '/tmp/mysql.sock'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.