今天看《高性能mysql》一书时,看到optimize table的命令可以重新组织表,就本地测试了下,执行结果如下:
mysql> optimize table psendohash;
+---------------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------------------+----------+----------+-------------------------------------------------------------------+
| yangjing.psendohash | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| yangjing.psendohash | optimize | status | OK |
+---------------------+----------+----------+-------------------------------------------------------------------+
2 rows in set (0.38 sec)
==============================
Table does not support optimize, doing recreate + analyze instead
为什么我的这个表不支持优化呢?
百度了一下,原来我这个表是innodb表,如下
mysql> show create table psendohash\G
*************************** 1. row ***************************
Table: psendohash
Create Table: CREATE TABLE `psendohash` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`url` varchar(255) NOT NULL,
`url_crc` int(10) unsigned NOT NULL DEFAULT '0',
`common` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ind_crc` (`url_crc`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
======================================================
innodb表如果想要重新组织一下表,可以使用下面的命令
mysql> alter table psendohash engine='InnoDB';
这样就可以整理表的一些碎片信息了。