Error: Unable to Connect to Local MySQL Server via Socket '/tmp/mysql.sock'
When attempting to connect to a local MySQL server during a test suite, an error occurs:
OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
Despite being able to connect to MySQL via the command line, the error persists. Even though ps aux shows the server is running and the socket exists, the connection fails.
This issue occurs frequently but not consistently, with the test suite sometimes running without errors. Using dtruss does not reproduce the problem.
While the client code is in Python, its relevance is uncertain.
If the host is changed to '127.0.0.1', a different error occurs:
DatabaseError: Can't connect to MySQL server on '127.0.0.1' (61)
Solution:
To resolve this issue, run the following command:
sudo /usr/local/mysql/support-files/mysql.server start
Alternatively, ensure that mysqld is running and attempt the connection again.
The above is the detailed content of Why Can't I Connect to My Local MySQL Server via Socket '/tmp/mysql.sock'?. For more information, please follow other related articles on the PHP Chinese website!