mysql查看表结构命令_mysql中optimize表命令测试例子

时间:2019-06-26  来源:mysql教程  阅读:

今天对myiam数据表进行批量删除后,发现空间没有回收,查了资料后,发现要通过optimize table来回收空间
测试如下,建立数据表:

 代码如下 CREATE TABLE `ttext` (
`id` int(11) DEFAULT NULL,
`context` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into ttext values( 1,’tiger1′),(2,’tiger2′),(3,’tiger3′);

然后重复执行insert into ttext select * from ttext;这样重复灌数据,很快数据文件就达到240MB,这个时候,可以确认的是id为1的数据占据了1/3的空间,那么接下来,可以删除delete from ttext where id=1;
按正常的想法,这样的操作后,空间应该有回收的,但是事实没有。
OPTIMIZE TABLE should be used if you have deleted a large part of a
table or if you have made many changes to a table with variable-length
rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns).
You can use OPTIMIZE TABLE to
reclaim the unused space and to defragment the data file.
通过资料来看可以通过optimize table ttext来回收相应的空间。
继续查看了官方手册后发现,这个操作与表所用的引擎有很大的关系。
innodb表必须是使用独立表空间的才行,其次在mysql5.1.27开始optimize table is also supported for partitioned tables.就是可以对分区表进行优化。
针对myisam引擎,使用optimize table 还有如下功能:
If the table has deleted or split rows, repair the table. [修复表]
If the index pages are not sorted, sort them. [索引未排序,会排序]
If the table’s statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.[若表的统计信息不是最新的,更新它]

mysql查看表结构命令_mysql中optimize表命令测试例子

http://m.bbyears.com/shujuku/55397.html

推荐访问:mysql删除表命令 mysql查看表内容命令
相关阅读 猜你喜欢
本类排行 本类最新