Home > Database > Mysql Tutorial > body text

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

Mary-Kate Olsen
Release: 2024-11-24 08:24:09
Original
380 people have browsed it

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

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

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

ps aux | grep mysql
Copy after login

If mysqld is not running, start it with:

sudo service mysql start
Copy after login

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!

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