简体   繁体   English

服务器关闭后出现MySQL错误2002

[英]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. 之后,我尝试连接到Mysql,但仅收到与mysql.sock相关的2002错误。 Anyway, I've fixed the issue with this solution: 无论如何,我已通过以下解决方案解决了该问题:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38) 无法通过套接字'/var/mysql/mysql.sock'连接到本地MySQL服务器(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 首先检查“ /var/log/mysqld.log”以查看文件/目录权限上的消息

If the MySQL server terminated unexpectedly, the MySQL socket was not reset after the reboot 如果MySQL服务器意外终止,则重启后未重置MySQL套接字

Due to power shutdown, the existing mysql process got terminated and socket file is not removed properly as this is not a graceful shutdown. 由于电源关闭,现有的mysql进程已终止,并且套接字文件未正确删除 ,因为这不是正常关闭。 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. 当套接字未被任何进程使用时,MySQL服务器不再尝试验证MySQL套接字的存在,因为检查套接字是否存在的块仅在套接字的另一端附加了PID时才重要。 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 如果没有mysqld pid,则套接字的存在可能不是有用的检查

  1. Why a shutdown caused this error? 为什么关机导致此错误?

    The error indicates that MySQL was not bound to its socket. 该错误表明MySQL未绑定到其套接字。 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. 它可能无法绑定到其套接字,因为似乎还有另一个进程(即没有完全关闭的MySQL实例)仍然绑定到了它。

  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. 安装UPS(不间断电源),该UPS可提供备用电源(由电池供电),同时向服务器发出主电源故障的信号。 This gives the server an opportunity to cleanly shutdown, so that its files are not left in a corrupt state. 这使服务器有机会彻底关闭,从而使其文件不处于损坏状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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