Home > Database > Mysql Tutorial > body text

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

Barbara Streisand
Release: 2024-11-12 07:05:02
Original
751 people have browsed it

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

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

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

Despite being able to connect via the mysql command line and confirming the server's status and socket existence, the error persists.

Potential Solutions

One proven solution is to execute the following command with superuser privileges:

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

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

If mysqld is not running, the following command can be used to start it:

sudo service mysqld start
Copy after login

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!

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