Home >Database >Mysql Tutorial >Why Can't I Connect to My Local MySQL Server Through the Socket '/tmp/mysql.sock' in Python, Despite the Server Running?
Troubleshooting MySQL Connection Error: "Can't Connect to Local MySQL Server Through Socket '/tmp/mysql.sock'"
Despite being able to establish connections to the MySQL server using the command line, an attempt to connect from a test suite in Python fails with the error:
OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
Verifications such as running 'ps aux | grep mysql' to confirm server process existence and 'stat /tmp/mysql.sock' to check for the socket's presence do not reveal any issues. Furthermore, a debugger opened under the exception clause allows successful connections using the same parameters.
The problem manifests intermittently and switching to '127.0.0.1' as host results in a different error:
DatabaseError: Can't connect to MySQL server on '127.0.0.1' (61)
Solution:
Executing the following command resolved the issue:
sudo /usr/local/mysql/support-files/mysql.server start
Additional Considerations:
The above is the detailed content of Why Can't I Connect to My Local MySQL Server Through the Socket '/tmp/mysql.sock' in Python, Despite the Server Running?. For more information, please follow other related articles on the PHP Chinese website!