今天,我注意到MySQL在崩溃的表上使用"CHECK“时的”奇怪“行为。首先,我收到了一个警告,比如“数据文件的大小是:*.应该是:*”,但是我仍然可以“插入/从表中选择”,没有问题,在插入几次之后,警告就消失了。我真的不明白这种行为的意义。
我的测试如下:
testing( id int(11) NOT AUTO_INCREMENT,lastname varchar(255) NULL,firstname varchar(255)默认值NULL,age int(11)默认值NULL,D12int (id) ENGINE=MyISAM DEFAULT CHARSET=latin1);检查桌子
mysql> check table testing.persons quick;
+-----------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------+
| testing.persons | check | warning | 1 client is using or hasn't closed the table properly |
| testing.persons | check | warning | Size of datafile is: 1877424 Should be: 1877376 |
| testing.persons | check | status | OK |
+-----------------+-------+----------+-------------------------------------------------------+
3 rows in set (0.01 sec)再检查一下桌子
mysql> check table testing.persons quick;
+-----------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------+
| testing.persons | check | warning | Size of datafile is: 1877424 Should be: 1877376 |
| testing.persons | check | status | OK |
+-----------------+-------+----------+-------------------------------------------------------+
2 rows in set (0.00 sec)插入新行
mysql> insert into testing.persons set firstname='somename', age='111';
Query OK, 1 row affected, 1 warning (0.01 sec)再检查一下桌子
mysql> check table testing.persons quick;
+-----------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------+
| testing.persons | check | warning | Size of datafile is: 1877424 Should be: 1877400 |
| testing.persons | check | status | OK |
+-----------------+-------+----------+-------------------------------------------------------+
2 rows in set (0.00 sec)插入另一行
mysql> insert into testing.persons set firstname='somename', age='222';
Query OK, 1 row affected, 1 warning (0.00 sec)再检查一下桌子
mysql> check table testing.persons quick;
+-----------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+----------+
| testing.persons | check | status | OK |
+-----------------+-------+----------+----------+
1 row in set (0.00 sec)最后,我们以状态"OK“结束,之前的警告”数据文件的大小是: 1877424..“神秘地消失了。
如果您使用“普通”表检查而不是“快速”检查运行上面的测试,则情况会变得更加混乱。在这种情况下,将立即检测到表已损坏,并最终将其标记为崩溃:
检查桌子
mysql> check table testing.persons;
+-----------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------+
| testing.persons | check | warning | 1 client is using or hasn't closed the table properly |
| testing.persons | check | warning | Size of datafile is: 1145136 Should be: 1145088 |
| testing.persons | check | error | Record-count is not ok; is 23857 Should be: 23856 |
| testing.persons | check | warning | Found 23857 key parts. Should be: 23856 |
| testing.persons | check | error | Corrupt |
+-----------------+-------+----------+-------------------------------------------------------+
5 rows in set (0.01 sec)再检查一下桌子
mysql> check table testing.persons;
+-----------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------+-------+----------+-------------------------------------------------------+
| testing.persons | check | warning | Table is marked as crashed |
| testing.persons | check | warning | 1 client is using or hasn't closed the table properly |
| testing.persons | check | warning | Size of datafile is: 1145136 Should be: 1145088 |
| testing.persons | check | error | Record-count is not ok; is 23857 Should be: 23856 |
| testing.persons | check | warning | Found 23857 key parts. Should be: 23856 |
| testing.persons | check | error | Corrupt |
+-----------------+-------+----------+-------------------------------------------------------+
6 rows in set (0.01 sec)<#>To摘要:
快速检查是警告,但是在几次插入之后,警告就消失了,检查显示表没有问题--似乎该表从未损坏或神秘地自动修复过。我完全不清楚为什么会有no问题插入或从表中插入或读取--不是在检查之前,而不是在检查之后,而另一个“正常”检查是立即将表标记为已损坏/崩溃。
发布于 2018-10-29 04:43:31
使用InnoDB而不是MyISAM。这将避免对CHECK和REPAIR的需求。
--myisam-recover-options=QUICKhttps://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_米舍尔德_美赛姆-恢复-选择
myisamchkhttps://dev.mysql.com/doc/refman/5.7/en/myisam-crash-recovery.html
https://dba.stackexchange.com/questions/221161
复制相似问题