北京SEO

mysql中optimize表命令测试例子

2019/10/10/17:37:49  阅读:1730  来源:谷歌SEO算法  标签: SEO技术

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

测试如下,建立数据表:

  1. CREATETABLE`ttext`(
  2. `id`int(11)DEFAULTNULL,
  3. `context`text
  4. )ENGINE=MyISAMDEFAULTCHARSET=latin1
  5. insertintottextvalues(1,’tiger1′),(2,’tiger2′),(3,’tiger3′);
  6. //开源代码phpfensi.com

然后重复执行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//phpfensi.com

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中optimize表命令测试例子 mysql中optimize表命令测试例子 mysql中optimize表命令测试例子

相关阅读

热门评论

SEO研究中心 SEO研究中心

SEO研究中心提供免费SEO公开课

总篇数170

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法