萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> 啟動MYSQL提示:Can’t connect to MySQL through socket ‘/tmp/mysql.sock’

啟動MYSQL提示:Can’t connect to MySQL through socket ‘/tmp/mysql.sock’

本文章來給大家介紹在啟動MYSQL時突然啟動不了,查看日志發現提示:Can’t connect to MySQL through socket ‘/tmp/mysql.sock’,後來百度了兩種解決辦法,有需要的朋友可參考。

啟動MYSQL是出現以下錯誤:

[root@www ~]# /usr/local/webserver/mysql/bin/mysqladmin -u root -p 12345678
Enter password:
/usr/local/webserver/mysql/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (111)’
Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists!

解決方法:

 代碼如下 復制代碼

[root@www ~]# /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.38-log Source distribution

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.

mysql>

mysql的參數說明:

/usr/local/webserver/mysql/bin/mysql –help | less

列舉常用參數:

-u, –user=name     User for login if not current user.
-p, –password[=name]
                      Password to use when connecting to server. If password is
                      not given it’s asked from the tty.
-S, –socket=name   Socket file to use for connection.


另一種解決辦法


我通過vim /etc/my.cnf,修改了[mysqld]選項下面的socket的值

 代碼如下 復制代碼 socket=/var/lib/mysql/mysql.sock

ok,mysqld可以啟動了

接下來,是mysql啟動不了,同樣,vim /etc/my.cnf,添加了如下腳本:

[mysql]

 代碼如下 復制代碼 socket=/var/lib/mysql/mysql.sock

然後,mysqladmin啟動不了,還是一樣,在[mysqladmin]下面socket值設置為同樣的路徑
ok,可以啟動了

copyright © 萬盛學電腦網 all rights reserved