简体   繁体   中英

Mysql error 2002 after server shutdown

The server had shut down yesterday because electricity had cut off. After that, I've tried connect to Mysql but only got the 2002 error related with mysql.sock. Anyway, I've fixed the issue with this solution:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)

sudo chmod -R 755 /var/lib/mysql/

But my question is: Why? Why a shutdown caused this error? How prevent this from happening again?

Check the '/var/log/mysqld.log' first to see messages on file/directory permission

If the MySQL server terminated unexpectedly, the MySQL socket was not reset after the reboot

Due to power shutdown, the existing mysql process got terminated and socket file is not removed properly as this is not a graceful shutdown. The MySQL server no longer attempts to verify the existence of a MySQL socket when the socket is not being used by any processes as the block checking for socket existence should only matter if there's a PID attached to the other end of the socket. On unclean reboot, this socket will persist and thus cause the failure.

Solution : I guess the simplest thing to do is remove the socket check. If there's no mysqld pids, then the existence of the socket may not be a useful check

  1. Why a shutdown caused this error?

    The error indicates that MySQL was not bound to its socket. It probably wasn't able to bind to its socket because it appeared that another process (namely the MySQL instance that did not shutdown cleanly) was still bound thereto.

  2. How prevent this from happening again?

    Install a UPS (uninterruptible power supply), which can provide backup power (from batteries) whilst signalling to the server that primary power has failed. This gives the server an opportunity to cleanly shutdown, so that its files are not left in a corrupt state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM