1 个数据库的 MySQL 超时,其他数据库正常 - MySQL 和 InnoDB 数据字典不同步

1 个数据库的 MySQL 超时,其他数据库正常 - MySQL 和 InnoDB 数据字典不同步

我无法连接到 MySQL 的特定数据库,即使从 phpMyAdmin 连接,也会出现以下错误:

#2002 - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) The server is not responding (or the local server's socket is not correctly configured).

在 MySQL 日志中我看到:

130404 1:18:09 InnoDB: MySQL and InnoDB data dictionaries are out of sync. InnoDB: Unable to find the AUTOINC column id in the InnoDB table strangedb/table. InnoDB: We set the next AUTOINC column value to 0, InnoDB: in effect disabling the AUTOINC next value generation. InnoDB: You can either set the next AUTOINC value explicitly using ALTER TABLE InnoDB: or fix the data dictionary by recreating the table. 130404 1:25:13 InnoDB: MySQL and InnoDB data dictionaries are out of sync. InnoDB: Unable to find the AUTOINC column id in the InnoDB table strangedb/table. InnoDB: We set the next AUTOINC column value to 0, InnoDB: in effect disabling the AUTOINC next value generation. InnoDB: You can either set the next AUTOINC value explicitly using ALTER TABLE InnoDB: or fix the data dictionary by recreating the table. 130404 1:25:13 InnoDB: Assertion failure in thread 139934538761984 in file handler/ha_innodb.cc line 8290 InnoDB: Failing assertion: auto_inc > 0 InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html InnoDB: about forcing recovery.

我可以确认 MySQL 对于所有其他表都运行正常。

我已经浏览过有关强制恢复的链接,但我不是 MySQL 忍者,我可以确定select * from strangedb.table;并且列出了内容,下一步该怎么做才能转储数据并重新导入到新表?

答案1

事实证明,这是像所提到的错误一样的损坏。我能够通过 MySQL 实用程序查看表的内容,并执行以下操作:

  1. 根据损坏表的现有架构创建一个新表
  2. 将数据从旧数据复制到新数据

以下命令:

USE strangedb;
CREATE TABLE table_new LIKE table;
INSERT table_new SELECT * FROM table;

一旦安全复制过来,我就可以删除旧表DROP TABLE table;并重命名救生艇表RENAME TABLE table_new TO table;

就我而言,这是没问题的,因为我没有任何关联约束,我可以想象,对于更复杂的场景,这些约束需要重新创建。

相关内容