Troubleshooting Connection Error to Local MySQL Server
When connecting to a local MySQL server through a Python client, users might encounter an error stating:
OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
Despite confirming that the MySQL server is running and the socket exists, the connection fails.
Resolving the Issue
To resolve this error, it is recommended to execute the following command as root:
sudo /usr/local/mysql/support-files/mysql.server start
Additionally, ensure that the mysqld process is running. To verify, run:
ps aux | grep mysql
If mysqld is not running, start it with:
sudo service mysql start
After executing these steps, attempt to connect to the MySQL server again. If the issue persists, check the configuration file for any errors or incorrect settings.
The above is the detailed content of Why Can't I Connect to My Local MySQL Server?. For more information, please follow other related articles on the PHP Chinese website!