溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么解決MySQL中的ERROR 2002(HY000)報(bào)錯(cuò)問題

發(fā)布時(shí)間:2021-11-19 10:37:13 來源:億速云 閱讀:4237 作者:iii 欄目:MySQL數(shù)據(jù)庫

本篇內(nèi)容主要講解“怎么解決MySQL中的ERROR 2002(HY000)報(bào)錯(cuò)問題”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么解決MySQL中的ERROR 2002(HY000)報(bào)錯(cuò)問題”吧!

[root@testmysql bin]# ./mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解決方法:

由于mysql 默認(rèn)的mysql.sock 是在/usr/local/mysql/data/mysql.sock,但linux系統(tǒng)總是去/tmp/mysql.sock查找,所以會(huì)報(bào)錯(cuò)

1.直接指定mysql通道

據(jù)我知道的(ps:我是菜鳥,請糾正),老版本(5.4之前)的是:/var/lib/mysql/mysql.sock

 在新版本中默認(rèn)是在/usr/local/mysql/data/mysql.sock,具體的可以去查看my.cnf文件里面

[root@testmysql bin]# ./mysql --socket=/usr/local/mysql/data/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.4-m7 Source distribution
Copyright (c) 2000, 2011, 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>

2. 創(chuàng)建符號連接:

為mysql.sock增加軟連接(相當(dāng)于windows中的快捷方式)。

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock


eg:
root@localhost ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@testmysql bin]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

插曲:有可能你在建立連接的時(shí)候出現(xiàn)下面的情況,
[root@testmysql bin]# ln -vs /usr/local/mysql/data/mysql.sock /tmp/mysql.sock
ln: creating symbolic link `/tmp/mysql.sock': File exists
沒關(guān)系,加上-f參數(shù)就可以了。-f的主要過程:先將同名的軟鏈接dd刪除,然后再創(chuàng)建硬鏈接dd

[root@testmysql bin]# ln -f /usr/local/mysql/data/mysql.sock /tmp/mysql.sock
[root@testmysql bin]# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.4-m7 Source distribution
Copyright (c) 2000, 2011, 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>

到此,相信大家對“怎么解決MySQL中的ERROR 2002(HY000)報(bào)錯(cuò)問題”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI