show create table history;
--------------------------
CREATE TABLE `foo` (
`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
mysql> OPTIMIZE TABLE history;
+----------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +----------+----------+----------+-------------------------------------------------------------------+ | test.foo | optimize | note | Table does not support optimize, doing recreate + analyze instead | | test.foo | optimize | status | OK | +----------+----------+----------+-------------------------------------------------------------------+
这里mysql给的提示是
Note>> Table does not support optimize, doing recreate + analyze instead
Status>> OK
也就是说 optimize table 对于innodb来说,无法作为
a single operation,实际的操作是:
ALTER TABLE test.foo ENGINE=InnoDB;
ANALYZE TABLE test.foo;
MySQL5.7已经推荐对于InnoDB的table使用 alter table table_name engine=innodb;语句的方式来进行表碎片优化。
底层实现的不同,参考:https://dev.mysql.com/doc/refman/5.7/en/optimize-table.html