以下是一个简单测试:
[mysql@odd employees]$ ls -alh t.ibd -rw-rw---- 1 mysql dba 24M 05-22 16:48 t.ibd 未optimize前、有24M mysql> optimize table t; +-------------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +-------------+----------+----------+-------------------------------------------------------------------+ | employees.t | optimize | note | Table does not support optimize, doing recreate + analyze instead | | employees.t | optimize | status | OK | +-------------+----------+----------+-------------------------------------------------------------------+ 2 rows in set (3.82 sec) --对于InnoDB的表、上面的内容并非报错、这是MySQL会帮你映射到:alter table table_name engine=\'InnoDB\'; --MyISAM不会有这种情况 [mysql@odd employees]$ ls -alh t.ibd -rw-rw---- 1 mysql dba 14M 05-22 16:49 t.ibd optimize后、剩14M
㈡ check
检查表或视图的有无错误
支持表引擎有:InnoDB和MyISAM
下面简单模拟一个测试:
mysql> check table t;
+-------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+-------------+-------+----------+----------+
| employees.t | check | status | OK |
+-------------+-------+----------+----------+
1 row in set (0.63 sec)
--没有错误的情况是这样的
--用vim打开t.frm随意编辑两把
mysql> check table t\G;
*************************** 1. row ***************************
Table: employees.t
Op: check
Msg_type: Error
Msg_text: Incorrect information in file: \'./employees/t.frm\'
*************************** 2. row ***************************
Table: employees.t
Op: check
Msg_type: error
Msg_text: Corrupt
2 rows in set (0.00 sec)
--报错了
㈢ analyze
用于收集优化器统计信息、和tuning相关、
这个命令对 MyISAM、BDB、InnoDB 存储引擎的表有作用
如果不想记录到binlog、也可加关键字local或者另外一个
mysql> analyze table t\G;
*************************** 1. row ***************************
Table: employees.t
Op: analyze
Msg_type: Error
Msg_text: Incorrect information in file: \'./employees/t.frm\'
*************************** 2. row ***************************
Table: employees.t
Op: analyze
Msg_type: error
Msg_text: Corrupt
2 rows in set (0.00 sec)来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26515977/viewspace-1208140/ ,如需转载,请注明出处,否则将追究法律责任。