在我们MySQL数据库维护工作中极力要避免的突发状况里面,表数据损坏无疑是一种非常糟糕的情况。
然而在实际情况中,有时候这些突发状况可能因为各种各样的因素还是残酷地需要我们直面处理。当这些突发状况发生时,也不要太过沮丧,如果我们能够冷静专业的面对,也许转机就在前方。
#/dev/null > innodb_index_stats.frm
#ll innodb_index_stats.frm
-rw-r----- 1 mysql mysql 0 Mar 24 08:41 innodb_index_stats.frm
2. 重启动数据库,无法正常启动
# sh shutdown.sh
Enter password:
# sh startup.sh
#sh login.sh
Enter password:
ERROR 2002 (HY000): Cant connect to local MySQL server through socket /data/mysql/db_order/mysql.sock (2)
3. 出现错误日志
2021-03-24T08:43:05.378517-05:00 0 [ERROR] InnoDB: The size of tablespace file ./mysql/innodb_index_stats.ibd is only 49674, should be at least 65536!
2021-03-24 08:43:05 0x7fc7430a4740 InnoDB: Assertion failure in thread 140493799966528 in file fil0fil.cc line 793
InnoDB: We intentionally generate a memory trap.
4. 修改参数文件,添加innodb_force_recovery = 6,强制启动数据库,存在丢失少量数据风险
# sh startup.sh
#sh login.sh #此时,正常启动
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.25-log Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or h for help. Type c to clear the current input statement.
5. 修改参数文件,还原innodb_force_recovery = 0,再重新启动
#sh shutdown.sh
#sh startup.sh
mysql> use mysql;
6. 删除损坏表
mysql> drop table innodb_index_stats;
ERROR 1051 (42S02): Unknown table mysql.innodb_index_stats
mysql> drop table if exists innodb_index_stats;
Query OK, 0 rows affected, 1 warning (1.07 sec)
# rm innodb_index_stats.frm
# rm innodb_index_stats.ibd
7. 进入系统目录,查看创建系统表脚本mysql_system_tables.sql
# cd /usr/local/mysql/share/
# ls *.sql
fill_help_tables.sql install_rewriter.sql mysql_sys_schema.sql mysql_system_tables.sql uninstall_rewriter.sql
innodb_memcached_config.sql mysql_security_commands.sql mysql_system_tables_data.sql mysql_test_data_timezone.sql
# cat *.sql|grep innodb_index_stats
SET @create_innodb_index_stats="CREATE TABLE IF NOT EXISTS innodb_index_stats (
SET @str=IF(@have_innodb <> 0, @create_innodb_index_stats, "SET @dummy = 0");
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with –A
mysql> select count(*) from innodb_index_stats;
+----------+
| count(*) |
+----------+
| 13 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from tt;
+----------+
| count(*) |
+----------+
| 407 | #损坏前数据笔数407
+----------+
1 row in set (0.00 sec)
#cd ./data/htest
#vi tt.ibd #打开删除任一字符
#sh shutdown.sh
#sh startup.sh
3. 无法登录数据库,log出现错误
#sh login.sh
Enter password:
ERROR 2002 (HY000): Cant connect to local MySQL server
through socket /data/mysql/db_order/mysql.sock (2)
#cat mysql.err|more
2021-03-25T08:34:42.683624-05:00 0 [ERROR] InnoDB: Database
page corruption on disk or a failed file read of page [page
id: space=124, page number=5]. You may have to recover from
a backup.
…
# mysqldump -uroot -psystem -S
/data/mysql/db_order/mysql.sock --single-transaction --
default-character-set=utf8 --set-gtid-purged=off --add-drop-
table --triggers --events --routines htest tt>tt.sql
mysqldump: [Warning] Using a password on the command line
interface can be insecure.
mysqldump: Got error: 2002: Cant connect to local MySQL
server through socket /data/mysql/db_order/mysql.sock (2)
when trying to connect
#sh login.sh
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.25-log Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or h for help. Type c to clear the current input statement.
mysql> use htest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> desc tt;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| TABLE_SCHEMA | varchar(64) | YES | | NULL | |
| TABLE_NAME | varchar(64) | YES | | NULL | |
| CREATE_TIME | datetime | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
#mysqldump -uroot -psystem -S /data/mysql/db_order/mysql.sock --single-transaction --default-character-set=utf8 --set-gtid-purged=off --add-drop-table --triggers --events --routines htest tt>tt.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `tt` at row: 339
[mysql@mysqltest1 bin]$ ll
total 32
-rw-r--r-- 1 mysql mysql 19304 Mar 25 08:51 tt.sql
7. 删除损坏表
mysql> drop table tt;
Query OK, 0 rows affected (1.39 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> source tt.sql;
Query OK, 0 rows affected (0.00 sec)
...
Query OK, 339 rows affected (0.08 sec)
Records: 339 Duplicates: 0 Warnings: 0
mysql> select count(*) from tt;
+----------+
| count(*) |
+----------+
| 339 | #相较407笔减少68笔数据,存在少量数据丢失风险
+----------+
1 row in set (0.00 sec)
需要说明的是:
innodb_force_recovery = 4代表相对比较安全,只有一些在损坏的多带带页面上的数据会丢失。
如果是innodb_force_recovery =6 ,数据库页将被留在一个陈旧的状态,这个状态反过来可以引发对B 树和其它数据库结构的更多破坏。
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129369.html
摘要:问题原因非正常关机导致没有把数据及时的写入硬盘。丢失的临时表临时表和基于语句的复制方式不相容。如果备库崩溃或者正常关闭,任何复制线程拥有的临时表都会丢失。临时表的特性只对创建临时表的连接可见。 主备复制过程中有很大可能会出现各种问题,接下来我们就讨论一些比较普遍的问题,以及当遇到这些问题时,如何解决或者预防问题发生。 1 数据损坏或丢失 问题描述:服务器崩溃、断电、磁盘损坏、内存或网络...
摘要:问题原因非正常关机导致没有把数据及时的写入硬盘。丢失的临时表临时表和基于语句的复制方式不相容。如果备库崩溃或者正常关闭,任何复制线程拥有的临时表都会丢失。临时表的特性只对创建临时表的连接可见。 主备复制过程中有很大可能会出现各种问题,接下来我们就讨论一些比较普遍的问题,以及当遇到这些问题时,如何解决或者预防问题发生。 1 数据损坏或丢失 问题描述:服务器崩溃、断电、磁盘损坏、内存或网络...
阅读 1347·2023-01-11 13:20
阅读 1685·2023-01-11 13:20
阅读 1133·2023-01-11 13:20
阅读 1860·2023-01-11 13:20
阅读 4101·2023-01-11 13:20
阅读 2705·2023-01-11 13:20
阅读 1386·2023-01-11 13:20
阅读 3598·2023-01-11 13:20