Home  >  Article  >  Database  >  Why Can't I Connect to My Local MySQL Server?

Why Can't I Connect to My Local MySQL Server?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-24 08:24:09393browse

Why Can't I Connect to My Local MySQL Server?

Troubleshooting Connection Error to Local MySQL Server

When connecting to a local MySQL server through a Python client, users might encounter an error stating:

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

Despite confirming that the MySQL server is running and the socket exists, the connection fails.

Resolving the Issue

To resolve this error, it is recommended to execute the following command as root:

sudo /usr/local/mysql/support-files/mysql.server start

Additionally, ensure that the mysqld process is running. To verify, run:

ps aux | grep mysql

If mysqld is not running, start it with:

sudo service mysql start

After executing these steps, attempt to connect to the MySQL server again. If the issue persists, check the configuration file for any errors or incorrect settings.

The above is the detailed content of Why Can't I Connect to My Local MySQL Server?. 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