Focus on cloud service provider activities
Notes on website operation and maintenance

Solve the error problem of "Can't connect to local MySQL server through socket" through personal testing

This problem was recorded in the document that helped a netizen solve the problem a few days ago, and the quantity collected here was put into the website. The student's website and server were still normal in the morning, and it was not clear whether it was his own trouble or other reasons that prevented him from accessing the website. So Lao Zuo helped him restart the server, restart Nginx and MYSQL, and then saw an error message.

Can 't connect to local MySQL server through socket '/tmp/mysql.sock '

It can be seen that the problem is here.

In fact, I used to help a netizen solve this problem in the BT panel. I directly backed up his database, uninstalled it, and reinstalled it. Anyway, the database problem can be directly deleted and reinstalled to solve the problem of possibly damaged files.

No, I'm not allowed to use this method here. First, analyze it because there is no "mysql.sock" file in the tmp directory.

Can we just copy this file in?

find / -name mysql.sock

Find out where this file is.

/var/lib/mysql/mysql.sock

Here is one. Then we need to modify the file:

vi /usr/local/mysql/my.cnf

Modify the socket file path to the known URL address above, so that no error is reported when you restart MYSQL after saving. Alternatively, we can create a soft route.

ln -s /var/lib/mysql.sock /tmp/mysql.sock

You do not need to modify the my.cnf file path.

Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( two )
Do not reprint without permission: Lao Zuo's Notes » Solve the error problem of "Can't connect to local MySQL server through socket" through personal testing


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge