When attempting to connect to a local MySQL server from a test suite, users may encounter the error:
OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
Despite being able to connect via the mysql command line and confirming the server's status and socket existence, the error persists.
One proven solution is to execute the following command with superuser privileges:
sudo /usr/local/mysql/support-files/mysql.server start
If this does not resolve the issue, it is essential to ensure that mysqld is running before attempting to connect to the MySQL server. To confirm this, run:
ps aux | grep mysql
If mysqld is not running, the following command can be used to start it:
sudo service mysqld start
Once the server is running, try connecting to MySQL again. If the error persists, there may be other underlying issues that require further investigation and troubleshooting.
The above is the detailed content of Why Can't I Connect to My Local MySQL Server Through Socket '/tmp/mysql.sock'?. For more information, please follow other related articles on the PHP Chinese website!