MySQL链接错误 No such file or directory, MySQL connection not working,What is mysql.sock file on linux, Cannot find mysql.sock

MySQL链接错误 No such file or directory, MySQL connection not working,What is mysql.sock file on linux, Cannot find mysql.sock
MySQL链接错误 No such file or directory, MySQL connection not working,What is mysql.sock file on linux, Cannot find mysql.sock

首先我们需要知道 mysql.sock 在哪里? 通过下面的命令可以查询位置:

mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name                           | Value                         |
+-----------------------------------------+-------------------------------+
| socket                                  | /yourpath/mysql.sock          |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)

 

获取到位置之后,打开php.ini 文件,或者在网站根目录下创建 php.ini 文件,找到或者修改  mysql.default_socket 为:

// 根据上面的查询,路径可以修改 /yourpath/mysql.sock; 如果你实在不知道路径,也可以尝试 /var/lib/mysql/mysql.sock 
mysql.default_socket = /path/to/mysql.sock

 

同样的方法,也可以在写在 ~/.my.cnf  里面:

[client]
socket=/var/lib/mysql-socket/mysql.sock

 

任选其一即可!

 

命令登录的时候可以用:

mysql -u root -p --socket=/absolute/path/of/your/mysql.sock

 

 

本文:MySQL链接错误 No such file or directory, MySQL connection not working,What is mysql.sock file on linux, Cannot find mysql.sock

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.