先列出問(wèn)題:
root@iZ:~# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/etc/run/mysql/mysql.sock' (2)
mysql.sock 這個(gè)文件在你的pc上的地址可能不同丁频,不過(guò)不影響犁嗅,通過(guò)提示找到相應(yīng)的目錄就行了熊痴,這個(gè)文件一般是會(huì)自動(dòng)生成的,所以遇到這種報(bào)錯(cuò)一般是不能自動(dòng)生成這個(gè)文件缩功,那么解決思路就出來(lái)了
簡(jiǎn)單粗暴點(diǎn)可以直接創(chuàng)建一個(gè)mysql.sock文件,但我一般不建議這樣都办,因?yàn)槟悴恢纼?nèi)容怎么寫嫡锌,當(dāng)然你可以在其他地方copy,這我就不講了
既然是不能自動(dòng)創(chuàng)建琳钉,為了找清楚問(wèn)題根源势木,就做了些讓人也疼的無(wú)聊測(cè)試,最后發(fā)現(xiàn)原來(lái)是文件夾權(quán)限問(wèn)題(真TM牙疼)歌懒,既然這樣解決起來(lái)就簡(jiǎn)單了啦桌,將mysql.sock所在目錄的權(quán)限改為777就行了
sudo chmod 777 /var/run/mysql
然后:
root@iZ:~/ $ sudo service mysql start [16:58:11]
* Starting MySQL database server mysqld [ OK ]
* Checking for tables which need an upgrade, are corrupt or were
not closed cleanly.
root@iZ:~/ $ mysql -uroot -p [16:58:35]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.5.50-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
貌似搞定了(牙疼),僅供后來(lái)者參考