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

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

Barbara Streisand
Barbara StreisandOriginal
2024-11-12 07:05:02738browse

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)")

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

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

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

sudo service mysqld start

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!

Statement:
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