Home > Database > Mysql Tutorial > Why Can't I Connect to My Local MySQL Server via Socket '/tmp/mysql.sock'?

Why Can't I Connect to My Local MySQL Server via Socket '/tmp/mysql.sock'?

Linda Hamilton
Release: 2024-11-12 08:43:02
Original
764 people have browsed it

Why Can't I Connect to My Local MySQL Server via Socket '/tmp/mysql.sock'?

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)")
Copy after login

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)
Copy after login

Solution:

To resolve this issue, run the following command:

sudo /usr/local/mysql/support-files/mysql.server start
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template