Lost connection to MySQL server at ‘reading initial communication packet錯誤解決

來源:互聯網
上載者:User

標籤:lost connection to mysql server at ‘reading initial communication packet

  今天線上mysql報錯,連不上了,報錯資訊大致為Lost connection to MySQL server at ‘reading initial communication packet。然後在網上找了些解決辦法,這邊一個一個來說明,方便以後在遇到這樣的問題不知道怎麼解決:

  最後尋找到的原因是/var/lib/mysql/下面的mysql.sock不見了,為什麼不見的還沒有找到,下面說下解決的辦法:


ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)

1、先查看 /etc/rc.d/init.d/mysqld status 看看mysql服務是否已經啟動.
另外看看是不是許可權問題.
$service mysqld start

$service mysql start
--我開始遇到的就是因為服務沒啟動,因為第一次玩mysql不是很熟悉,呵呵。

2、確定你的mysql.sock是不是在那個位置,
mysql -u 你的mysql使用者名稱 -p -S /var/lib/mysql/mysql.sock

3、如果是許可權問題,則先改變許可權 #chown -R mysql:mysql /var/lib/mysql

[[email protected] ~]# /etc/init.d/mysqld start
啟動 MySQL: [ 確定 ]
[[email protected] ~]# mysql -uroot -p

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
原因是,/var/lib/mysql 的存取權限問題。

shell> chown -R mysql:mysql /var/lib/mysql

接著啟動伺服器

shell> /etc/init.d/mysql start

伺服器正常啟動後察看 /var/lib/mysql 自動產生mysql.sock檔案。

4、修改/etc/my.conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/usr/local/mysql

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]
socket=/var/lib/mysql/mysql.sock

如果發現問題依舊,嘗試運行/etc/init.d/mysql start報錯:Starting MySQLCouldn‘t find MySQL manager or server

  

    

    

Lost connection to MySQL server at ‘reading initial communication packet錯誤解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.