记一次MySQL故障处理
进宝塔面板看到系统负载100%,内存占用90%,预感要出事了,果然不一会MySQL崩掉了。
Mysql进程被系统强行kill掉以后,尝试启动MySQL报错:
[root@VM-4-10-centos data]# service mysqld restart ERROR! MySQL server PID file could not be found! Starting MySQL... ERROR! The server quit without updating PID file (/www/server/data/VM-4-10-centos.pid). [root@VM-4-10-centos data]# service mysql restart Redirecting to /bin/systemctl restart mysql.service Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@VM-4-10-centos data]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查看目录
/www/server/data/
发现.pid文件消失,.err文件还在
考虑到权限问题,cp了一个err文件作为pid文件,重新启动mysqld服务,文件被秒删。
查看磁盘占用情况,没有占满
修改my.cnf文件,将恢复选项从0-4调了一遍也没用,查看mysql报错日志
2021-05-22 20:55:11 2740 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace ctf/glowworm_attacks uses space ID: 52 at filepath: ./ctf/glowworm_attacks.ibd. Cannot open tablespace ctf2/glowworm_attacks which uses space ID: 52 at filepath: ./ctf2/glowworm_attacks.ibd 2021-05-22 20:55:11 2b8e375f9800 InnoDB: Operating system error number 2 in a file operation. InnoDB: The error means the system cannot find the path specified. InnoDB: If you are installing InnoDB, remember that you must create InnoDB: directories yourself, InnoDB does not create them. InnoDB: Error: could not open single-table tablespace file ./ctf2/glowworm_attacks.ibd InnoDB: We do not continue the crash recovery, because the table may become InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. InnoDB: To fix the problem and start mysqld: InnoDB: 1) If there is a permission problem in the file and mysqld cannot InnoDB: open the file, you should modify the permissions. InnoDB: 2) If the table is not needed, or you can restore it from a backup, InnoDB: then you can remove the .ibd file, and InnoDB will do a normal InnoDB: crash recovery and ignore that table. InnoDB: 3) If the file system or the disk is broken, and you cannot remove InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
发现两个库出现问题,不知道这个库是什么时候创建的,也不知道用来做什么的,备份了一下,把文件删除了
最后注释了my.cnf的恢复语句,删除了mysql数据目录里的index,又拷贝来一个pid文件后,mysql终于能跑起来了。
恢复删掉的库后使用正常
[root@VM-4-10-centos ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ctf2这个库应该都没有在用,不清楚为什么mysql崩溃以后坏的是这个库