我有一台装有 ISPConfig 3.1 的 Ubuntu 16.04 服务器。
由于某种原因,服务器在一个高负载的进程上工作过多,所以我关闭电源并重新启动了机器。之后,Mysql 停止工作,无法再重新启动。
我检查了 /var/log/mysql/error.log 的错误日志,但它是空的。
当我尝试重新启动服务时收到以下消息:
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
systemctl 状态 mysql.service:
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since jue 2019-08-22 18:58:05 -04; 41s ago
Docs: man:systemd-sysv-generator(8)
Process: 12020 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS)
Process: 12056 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
journalctl-xe:
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0x955d0c]
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0x93b08e]
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0x93cd7f]
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0xa1dd9d]
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0xa670b6]
ago 22 18:58:32 servidor1 mysqld[12230]: /usr/sbin/mysqld[0x9ba375]
ago 22 18:58:32 servidor1 mysqld[12230]: /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f8ba90256ba]
ago 22 18:58:32 servidor1 mysqld[12230]: x86_64/clone.S:111(clone)[0x7f8ba84cc41d]
ago 22 18:58:32 servidor1 mysqld[12230]: The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
ago 22 18:58:32 servidor1 mysqld[12230]: information that should help you find out what is causing the crash.
ago 22 18:58:52 servidor1 dovecot[904]: auth-worker(12400): Error: sql([email protected],152.172.252.195): Password query failed: Not connected to database
ago 22 18:58:52 servidor1 dovecot[904]: auth: Error: auth worker: Aborted PASSV request for [email protected]: Lookup timed out
ago 22 18:58:52 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:58:53 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:58:54 servidor1 dovecot[904]: imap-login: Aborted login (auth failed, 1 attempts in 62 secs): user=<[email protected]>, method=PLAIN, rip=152.172.252.19
ago 22 18:58:58 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:59:01 servidor1 CRON[12687]: pam_unix(cron:session): session opened for user root by (uid=0)
ago 22 18:59:01 servidor1 CRON[12686]: pam_unix(cron:session): session opened for user root by (uid=0)
ago 22 18:59:01 servidor1 CRON[12688]: (root) CMD (/usr/local/ispconfig/server/cron.sh 2>&1 | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log
ago 22 18:59:01 servidor1 CRON[12689]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.l
ago 22 18:59:01 servidor1 CRON[12686]: pam_unix(cron:session): session closed for user root
ago 22 18:59:23 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:59:25 servidor1 su[12004]: pam_unix(su:session): session closed for user root
ago 22 18:59:25 servidor1 sudo[12003]: pam_unix(sudo:session): session closed for user root
ago 22 18:59:27 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:59:28 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:59:33 servidor1 dovecot[904]: auth-worker(12673): Error: mysql(localhost): Connect failed to database (dbispconfig): Can't connect to local MySQL server throug
ago 22 18:59:34 servidor1 sudo[12790]: surempresa : TTY=pts/20 ; PWD=/home/surempresa ; USER=root ; COMMAND=/bin/su
ago 22 18:59:34 servidor1 sudo[12790]: pam_unix(sudo:session): session opened for user root by (uid=0)
ago 22 18:59:34 servidor1 su[12809]: Successful su for root by root
ago 22 18:59:34 servidor1 su[12809]: + /dev/pts/20 root:root
ago 22 18:59:34 servidor1 su[12809]: pam_unix(su:session): session opened for user root by (uid=0)
ago 22 18:59:34 servidor1 su[12809]: pam_systemd(su:session): Cannot create session: Already running in a session
但是,在我尝试了这篇文章中的解决方案后,我设法重新启动了该服务:
所以我设置:
[mysqld]
innodb_force_recovery = 9
但是,由于一些数据库表现在是只读的,所以它不能很好地工作。
我该怎么做呢?谢谢。
答案1
对于任何因为 MySQL 数据库崩溃而需要(或使用) 而阅读本文的人innodb_force_recovery
,请注意您应该从 开始innodb_force_recovery=1
,然后慢慢地进行操作,直到 MySQL 启动。如果您能够转储值为innodb_force_recovery
``3 或更低的表,那么您可以确保所有数据、存储过程、触发器和视图都是完整的。
在某些情况下,您可能需要使用4
或更高级别。请注意,一旦达到此级别,数据损坏的可能性就很高。最高innodb_force_recovery
值为6
,所有更高值均视为6
。如果您在这里,我真诚地希望您有一个最近的备份可供恢复。
因为损坏的 InnoDB 表永远不再值得信任,所以处理这种情况的正确方法是删除数据库并恢复。这将重建所有文件。
从命令行:
- 转储数据库(如果您没有最近的备份可以重建):
sudo mysqldump --routines --triggers --add-drop-database --add-drop-table DB_NAME > panic.sql
- 停止 MySQL:
sudo service mysqld stop
- 删除损坏的数据库文件:
cd /var/lib/mysql rm -Rf <DB_NAME>
- 注释掉以下
innodb_force_recovery
行my.cnf
:# innodb_force_recovery=…
- 重新启动 MySQL:
sudo service mysqld start
- 以以下身份连接到 MySQL
root
并导入数据库:mysql> tee import_database.log mysql> source panic.sql
从此时,您可能需要确认用户帐户能够连接并使用数据库。
希望您永远不需要对生产系统执行此操作……