Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 解決辦法

來源:互聯網
上載者:User

標籤:

啟動mysql 報錯:

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

1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已經啟動.
另外看看是不是許可權問題.

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

3、試試:service mysqld start

4、如果是許可權問題,則先改變許可權 #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‘ (111)
原因是,/var/lib/mysql 的存取權限問題。

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

接著啟動伺服器

shell> /etc/init.d/mysql start

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

但是我的問題仍然沒有得到解決。

問題終於解決:
方法: 修改/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
是mysqld服務沒啟,運行/usr/local/mysql/bin/mysqld_safe &

問題解決。

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 解決辦法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.