【原創】大叔問題定位分享(32)mysql故障恢復


mysql啟動失敗,一直crash,報錯如下:

2019-03-14T11:15:12.937923Z 0 [Note] InnoDB: Uncompressed page, stored checksum in field1 1118110825, calculated checksums for field1: crc32 2889511119/2044155182, innodb 4005355497, none 3735928559, stored checksum in field2 1244127832, calculated checksums for field2: crc32 2889511119/2044155182, innodb 952099433, none 3735928559, page LSN 4 2819295388, low 4 bytes of LSN at page end 2486405135, page number (if stored to page already) 3971, space id (if created with >= MySQL-4.1.1 and stored already) 1840
InnoDB: Page may be an index page where index id is 6640
2019-03-14T11:15:12.937950Z 0 [Note] InnoDB: Index 6640 is `GEN_CLUST_INDEX` in table `zabbix`.`history_uint`
2019-03-14T11:15:12.937955Z 0 [Note] InnoDB: It is also possible that your operating system has corrupted its own file cache and rebooting your computer removes the error. If the corrupt page is an index page. You can also try to fix the corruption by dumping, dropping, and reimporting the corrupt table. You can use CHECK TABLE to scan your table for corruption. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery.

看起來是文件損壞了,我有備庫,所以希望主庫盡快恢復,然后再恢復數據,直接移走有問題的frm和ibd,再啟動,報錯:

2019-03-14T11:23:37.246589Z 0 [ERROR] InnoDB: Tablespace 1840 was not found at ./zabbix/history_uint.ibd.
2019-03-14T11:23:37.246594Z 0 [ERROR] InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace.
2019-03-14T11:23:37.247018Z 0 [ERROR] InnoDB: Cannot continue operation.

修改my.cnf

innodb_force_recovery=1

再重啟正常,嘗試重新新建表,但是各種報錯:

mysql> CREATE TABLE `history` (
    ->   `itemid` bigint(20) unsigned NOT NULL,
    ->   `clock` int(11) NOT NULL DEFAULT '0',
    ->   `value` double(16,4) NOT NULL DEFAULT '0.0000',
    ->   `ns` int(11) NOT NULL DEFAULT '0',
    ->   KEY `history_1` (`itemid`,`clock`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ERROR 1813 (HY000): Tablespace '`zabbix`.`history`' exists.
mysql> alter table history discard tablespace;
ERROR 1146 (42S02): Table 'zabbix.history' doesn't exist
mysql> drop tablespace history;
ERROR 1529 (HY000): Failed to drop TABLESPACE history
mysql> drop table history;
ERROR 1051 (42S02): Unknown table 'zabbix.history'

完全沒有辦法操作,這時的解決方法是:

  • CREATE TABLE bad_table ENGINE=MyISAM ...
  • rm bad_table.ibd
  • DROP TABLE bad_table
  • CREATE TABLE bad_table ENGINE=INNODB ...

然后再恢復數據

 

也有可能報錯時並沒有指出具體出錯的文件或者表,類似

2019-11-25T12:54:59.258844Z 0 [ERROR] InnoDB: Database page corruption on disk or a failed file read of page [page id: space=0, page number=593]. You may have to recover from a backup.

這時需要使用mysqlcheck命令來檢查某個數據庫

# mysqlcheck -uroot -proot $dbname

也可以檢查所有的數據庫

# echo 'show databases'|mysql -uroot -proot|xargs -i mysqlcheck -uroot -proot {}

輸出結果為兩列,第二列是status,正常為OK,其他值為異常,找到異常的表,刪除或者將數據導出后再導入,則問題修復;

 

參考:
https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM