解決Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";
http://blog.csdn.net/hjf161105/article/details/78850658
最近租了一個阿里云云翼伺服器,趁著自己還是一個學生,享受一下優惠。我租的是阿里雲Ubuntu16.04版本的伺服器,在搭建mysql的時候,一開始是可以執行的,由於某次手抽,把mysql的套接字檔案不小心刪除了,然後無論怎麼解除安裝重灌,都出現了這個問題:
- [email protected]:~# mysql -uroot -p
- Enter password:
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
我出現的問題是:找不到mysql.sock,如果你可以執行
- find / -name mysql.sock
但是,我執行了這條語句之後,並沒有任何反應,沒有找到mysql.sock檔案。
在這之前,需要明白mysql.sock這個檔案有什麼用?
連線localhost通常通過一個Unix域套接字檔案進行,一般是/tmp/mysql.sock。如果套接字檔案被刪除了,本地客戶就不能連線。這可能發生在你的系統執行一個cron任務刪除了/tmp下的臨時檔案。
如果你因為丟失套接字檔案而不能連線,你可以簡單地通過重啟伺服器重新建立得到它。因為伺服器在啟動時重新建立它。
如果和我一樣,重啟伺服器還是沒有任何變化,你可以先執行下面的語句:
- # mysql -uroot -h 127.0.0.1 -p
如果套接字檔案被一個cron任務刪除,問題將重複出現,除非你修改cron任務或使用一個或使用一個不同的套接字檔案,我的解決辦法是重新指定一個不同的套接字,或者說,我現在沒有mysql.sock檔案,所以我要想辦法生成一個。
首先,更改my.cnf檔案,我的伺服器中的目錄為/etc/my.cnf,如果沒有的話可以用find去查詢,
接下來就是儲存退出,然後確保這個目錄存在,並且將這個目錄的許可權修改一下
- # chmod 777 /var/lib/mysql
- # service mysql restart
- # service mysqld restart
- [email protected]:~# service mysqld start
- Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalc
- tl -xe" for details.
這個時候,提示可以輸入systemctl status mysqld.service去檢視具體的失敗原因,於是:
****************************************************************************************
[email protected]:~# systemctl status mysqld.service
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysqld; bad; vendor preset: enabled)
Active: failed(Result: exit-code) since 三 2017-12-20 10:38:30 CST; 45s ago
Docs: man:systemd-sysv-generator(8)
Process: 2154 ExecStart=/etc/init.d/mysqld start (code=exited, status=1/FAILURE)
12月 20 10:38:29 iZufkfljcZ systemd[1]: Starting LSB: start and stop MySQL...
12月 20 10:38:29 iZufkfljcZ mysqld[2154]: Starting MySQL
12月 20 10:38:29 iZufkfljcZ mysqld_safe[2689]:Logging to '/var/log/mysql/error.log'.
12月 20 10:38:29 iZufkfljcZ mysqld_safe[2693]:Directory '/var/run/mysqld' for UNIX socket file don't exists.
12月 20 10:38:30 iZufkfljcZ mysqld[2154]: . * The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
12月 20 10:38:30 iZufkfljcZ systemd[1]: mysqld.service: Control process exited, code=exited status=1
12月 20 10:38:30 iZufkfljcZ systemd[1]: Failed to start LSB: start and stop MySQL.
12月 20 10:38:30 iZufkfljcZ systemd[1]: mysqld.service: Unit entered failed state.
12月 20 10:38:30 iZufkfljcZ systemd[1]: mysqld.service: Failed with result 'exit-code'.
****************************************************************************************
根據提示可知,/var/run/mysqld目錄不存在,也就是說mysqld服務重啟需要這個目錄,那就建一個吧:
- [email protected]:~# mkdir /var/run/mysqld
- [email protected]:~# chmod 777 /var/run/mysqld/
- [email protected]:~# service mysqld start
- [email protected]:~#
- [email protected]# ls /var/run/mysqld
- mysqld.pid mysqld.sock mysqld.sock.lock
- [email protected]:/var/run/mysqld# mysql -uroot -p -S /var/run/mysqld/mysqld.sock
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 4
- Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
- Copyright (c) 2000, 2017, 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>
這麼一執行,發現好像可以了,那接下來好辦了,我們把之前改的配置改回來就行了,之前的目錄應該是/tmp/mysql.sock,我們可以建立一個軟連線連上去就可以了,
- [email protected]:~# ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
- [email protected]:~# ls /tmp/
- mysql.sock
到此為止,我們的mysql應該已經完全修復了,那麼我們再測試一下吧:
- [email protected]:/var/run/mysqld# mysql -uroot -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 5
- Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
- Copyright (c) 2000, 2017, 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>
相關推薦
原來如此簡單:解決Mac上的Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mac os上第一次使用mysql,果然出現了問題,安裝好mysql的dmg後,在終端輸入mysql,結果出現 hrfpc:~ hrf$ mysql ERROR 2002 (HY000): Can't connect to local MySQL server thr
解決Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’錯誤
剛安裝完mysql,進行執行測試,報Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’錯誤, [[email protected] mysql]# /usr/local/my
解決Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";
http://blog.csdn.net/hjf161105/article/details/78850658最近租了一個阿里云云翼伺服器,趁著自己還是一個學生,享受一下優惠。我租的是阿里雲Ubuntu16.04版本的伺服器,在搭建mysql的時候,一開始是可以執行的,由於某
完美解決Can't connect to local MySQL server through socket mysql.sock
We’ll be doing this in the following order. Stopping the MySQL server Create a new data directory and move the content from the old da
Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) " 解決辦法
cenos版本:6 完全安裝教程安裝,但就是卡在service mysqld start。網上的解釋都太繁瑣了,直接解除安裝乾淨重灌就行了。 方法: yum -y remove mysql(安裝的sql版本) 然後重點來了 find / -name mysql ,找到
解決 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
###親測有效 電腦經過一番波折終於回到我的手中,然後美滋滋的開啟電腦,準備開啟資料庫看看資料,發現連不上資料庫了。報錯 ERROR 2002 (HY000): Can't connect to local MySQL server through socket
{linux} Can't connect to local MySQL server through socket '/tmp/mysql.sock'
安裝mysql成功後,登陸mysql -uroot -p輸入密碼發生 mysql -uroot -p Enter password: ERROR 2002 (HY000): Can't connect
MySql 報錯ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
MySql 報錯ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) 這個錯是連結時報的錯,要連結必須啟動。修復的時候首先要啟動m
mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決方法:原因:mysql目錄沒有許可權 方法:執行 sudo chown -R mysql:mysql /usr/local/var/mysql 給了許可權之後重啟 sudo mysql.ser
mac終端執行mysql出現Can't connect to local MySQL server through socket '/tmp/mysql.sock'
開啟mac的終端,輸入mysql -u root -p****** 之後,出現Can't connect to local MySQL server through socket '/tmp/mysql.sock',十分驚訝,因為幾個月前執行這個命令還是成功的。然後我就cd
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’(2) 是一個比較常見的資料庫報錯,而昨天我們的伺服器也報了這個錯誤,所有服務全掛,而且
CentOS下面ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
文章轉自:https://www.cnblogs.com/Lam7/p/6090975.html有時候,當我們使用“mysql”、“mysqladmin”、“mysqldump”等命令管理資料庫時,伺服器丟擲類似如下錯誤:一、錯誤現場還原:下面我們通過三種方式來連線,然後觀察提示的錯誤資訊:1、直接使用“my
記一次 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’(2) 排錯流程
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’(2) 是一個比
遇到問題----Can't connect to local MySQL server through socket '/tmp/mysql.sock'
Can't connect to local MySQL server through socket '/tmp/mysql.sock' 提示得很清楚 就是連線的時候要/tmp路徑下找一個mysql.sock檔案 這裡沒有找到。 那我們應該怎麼辦呢 我們可以查詢下哪
連接Mysql提示Can’t connect to local MySQL server through socket的解決方法
127.0.0.1 方式 mic div conn 三種 問題 ati my.cnf 轉:http://aiezu.com/article/mysql_cant_connect_through_socket.html 有時候,當我們使用“mysql”、“mysqladmin
Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ 解決
bsp 文件讀取 my.cnf dir spa min pre 啟動 style mysql 改變 basedir 目錄,啟動後客戶端登陸出現 Can’t connect to local MySQL server through socket ‘/var/lib/mys
連線Mysql提示Can’t connect to local MySQL server through socket各種情況以及解決辦法(轉載)
轉自:http://www.aiezu.com/db/mysql_cant_connect_through_socket.html 產生此問題的原因一般有兩個: 1、mysql服務未正常執行: 由於mysql的socket檔案是由mysqld服務啟動時建立的,如果mysqld服務未正常啟動,soc
連接Mysql提示Can’t connect to local MySQL server through socket各種情況以及解決辦法(轉載)
文件的 字符 -o exe localhost user body external The 轉自:http://www.aiezu.com/db/mysql_cant_connect_through_socket.html 產生此問題的原因一般有兩個: 1、mysql服務
Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ 解決
mysql 改變 basedir 目錄,啟動後客戶端登陸出現 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ 問題,解決方式如下: /etc/my.cnf &nbs
解決mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket錯誤的方法
ps -A | grep -i mysql kill 列出來的程序 service mysql start 我的問題就解決了 Fedora8啟動mysql 報錯: ERROR 2002 (HY000): Can’t connect to local MySQL