: Can't connect to local MysQL server through socket '/tmp/mysql.sock' (111)
时间: 2023-08-25 09:10:33 浏览: 151
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
This error usually occurs when the MySQL server is not running or the socket file is not in the expected location. Here are a few steps you can try to resolve the issue:
1. Check if the MySQL server is running by executing the following command in your terminal:
`sudo service mysql status`
If it's not running, start the MySQL server using the following command:
`sudo service mysql start`
2. If the server is already running, make sure the socket file exists in the specified location (`/tmp/mysql.sock`). If it doesn't exist, you can create a symbolic link to the actual socket file. Run the following commands:
```
sudo mkdir /var/run/mysqld
sudo ln -s /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock
```
3. If the above steps don't work, it's possible that your MySQL configuration file has the wrong socket location. Open the MySQL configuration file (`/etc/mysql/my.cnf` or `/etc/my.cnf`) and check the `socket` parameter under the `[mysqld]` section. Update it to the correct socket file path.
After making any changes, restart the MySQL server using `sudo service mysql restart` and try connecting again.
阅读全文