Home > Database > Mysql Tutorial > body text

Why Can't I Connect to My Local MySQL Server Through Socket, But the Command Line Works?

DDD
Release: 2024-11-09 21:50:02
Original
829 people have browsed it

Why Can't I Connect to My Local MySQL Server Through Socket, But the Command Line Works?

Troubleshooting "Can't Connect to Local MySQL Server Through Socket" Error

When attempting to establish a connection to a local MySQL server during testing, a user encountered an OperationalError with the following message:

OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
Copy after login

Despite the error, the user was able to connect successfully using the mysql command line program. As the server appeared to be running and the socket existed, the cause remained elusive.

Investigation

The issue exhibited intermittent behavior, sometimes affecting the test suite and other times not. Switching to use the host 127.0.0.1 resulted in a different error:

DatabaseError: Can't connect to MySQL server on '127.0.0.1' (61)
Copy after login

Solution

The suggested solution was to execute the following command as a superuser:

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

This command successfully started the MySQL server and allowed the user to establish a connection without encountering the previous error.

Additional Considerations

If the above solution does not resolve the issue, it is advisable to verify that mysqld is running and then attempt to connect to the server.

The above is the detailed content of Why Can't I Connect to My Local MySQL Server Through Socket, But the Command Line Works?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template