OPTIMIZE TABLE
INNODB 不支持 mysql> OPTIMIZE TABLE t;
+--------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------+----------+----------+-------------------------------------------------------------------+
| test.t | optimize | note | Table does not support optimize, doing recreate + analyze instead | //INNODB
| test.t | optimize | status | OK |
+--------+----------+----------+-------------------------------------------------------------------+
2 rows in set (0.24 sec)
mysql> show create table t;
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.18 sec)
使 OPTIMIZE table 对 innodb 支持
mysqld --datadir=/data --basedir=/usr/local/mysql56 --user=mysql --gdb --skip-new
mysql> OPTIMIZE TABLE t;
Query OK, 0 rows affected (0.27 sec)
Records: 0 Duplicates: 0 Warnings: 0
原理:映射为 alter table
By default, OPTIMIZE TABLE does not work for tables created using any other storage engine and returns a result indicating this lack of support. You can make OPTIMIZTABLE work for other storage engines by starting mysqld with the --skip-new option. In this case, OPTIMIZE TABLE is just mapped to ALTER TABLE.
OPTIMIZE TABLE continues to use ALGORITHM=COPY under the following conditions: When the old_alter_table system variable is turned ON. set old_alter_table=on; //alter table 修改表采用 algorithm=copy 方式 When the mysqld --skip-new option is enabled.
google: Everytime you do optimize MySQL, by using mysqlcheck -A -o or using ./mysql_optimize from here.
You may see the output Table does not support optimize, doing recreate + analyze instead. It is because the table that you are using is InnoDB. You can optimize the InnoDB tables by using this. ALTER TABLE table.name ENGINE='InnoDB'; This will create a copy of the original table, and drop the original table, and replace to the original place. Although this is safe, but I suggest you do backup and test first before doing this.
mysql> ALTER TABLE t ENGINE='InnoDB';
Query OK, 0 rows affected (0.29 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from t;
+---+
| a |
+---+
| 7 |
+---+
1 row in set (0.01 sec)
innodb的数据库不支持optimize,可以用ALTER TABLE table.name ENGINE='InnoDB';
该方法会对旧表以复制的方式新建一个新表,然后删除旧表。虽然这个过程是安全的,
但是在进行操作时还是先进行备份为好
MyISAM:正常
mysql> show create table t;
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) mysql> OPTIMIZE TABLE t;
+--------+----------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+--------+----------+----------+----------+
| test.t | optimize | status | OK |
+--------+----------+----------+----------+
1 row in set (0.00 sec)
OPTIMIZE TABLE的更多相关文章
- OPTIMIZE TABLE 小解
首先看一下语法: OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [, tbl_name] ... 我们知道mysql存储引擎里面的数据和索 ...
- 使用 SQL 命令 OPTIMIZE TABLE 释放表空间
前提: 1.删除了表的一大部分: 2.已经对含有可变长度行的表(含有VARCHAR, BLOB或TEXT列的表)进行了很多更改. ----------------------------------- ...
- mysql下优化表和修复表命令使用说明(REPAIR TABLE和OPTIMIZE TABLE)
随着mysql的长期使用,可以修复表来优化,优化时减少磁盘占用空间.方便备份. REPAIR TABLE `table_name` 修复表 OPTIMIZE TABLE `table_name` 优化 ...
- mysql中OPTIMIZE TABLE的作用
在使用mysql的时候有时候,可能会发现尽管一张表删除了许多数据,但是这张表表的数据文件和索引文件却奇怪的没有变小.这是因为mysql在删除数据(特别是有Text和BLOB)的时候,会留下许多的数据空 ...
- OPTIMIZE TABLE的作用--转载
当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删 除操作后在数据文件中留下碎片所致.Discuz! 在系统数设置界面提供了数据表优化的功能,可以去除删除操作后留下的数据文件 ...
- optimize table table_name myisam mysql自动清除删除过留下的空记录
optimize table table_name 这个可以清除你表里面的空记录,每次清除的时候记得锁表 lock tables table_name write|read; unlock tabl ...
- 使用OPTIMIZE TABLE命令来整理表碎片实践
操作环境:ubuntu 14.10 mysql 5.6.25 对含有BLOB或TEXT字段的表,若经常做修改或删除类的操作,需要定期执行OPTIMIZE TABLE命令来整理碎片. 1.creat ...
- optimize table 表优化问题
语法: optimize table '表名' 一,原始数据 1,数据量 2,存放在硬盘中的表文件大小 3,查看一下索引信息 索引信息中的列的信息说明. Table :表的名称.Non_unique: ...
- 实例说明optimize table在优化MySQL时很重要
今天在看CU的时候,发现有人问有关optimize来表优化的问题,当年因为这个问题,困扰我很长一段时间,今天有空我把这个问题,用实际数据来展示出来,让大家可以亲眼来看看,optimize table的 ...
随机推荐
- linux相关办公软件汇总
ubuntu pdf阅读器 FoxitReader_1.1.0_i386.deb ubuntu 下的PDF阅读器(超级好使) Ubuntu下的chm和PDF阅读器 ubuntu便签软件xpad sud ...
- Linq中SingleOrDefault、FirstOrDefault的用法
1.SingleOrDefault和FirstOrDefault的区别 SingleOrDefault 只取一个 如果没有数据等于 null, 如果>1 异常 FirstOrDefault ...
- A标签执行JS脚本
A标签执行JS脚本 分类: Web2012-12-25 22:48 1368人阅读 评论(0) 收藏 举报 前言 A标签是html中常用的标签,它与button按钮是实现页面跳转的两种最常用的方式,经 ...
- isIOS9
function isIOS9() { //获取固件版本 var getOsv = function () { var reg = /OS ((\d+_?){2,3})\s/; if (navigat ...
- Native Fullscreen JavaScript API (plus jQuery plugin)
http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ HTML5 <video> is gre ...
- MySQL海量数据查询优化策略
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- Linux文件类型与扩展名
Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念.我们通过一般应用程序而创建的比如file.txt.file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux文 ...
- POJ -- 3842
An Industrial Spy Description Industrial spying is very common for modern research labs. I am such ...
- 【原】SparkContex源码解读(二)
版权声明:本文为原创文章,未经允许不得转载. 继续前一篇的内容.前一篇内容为: SparkContex源码解读(一)http://www.cnblogs.com/yourarebest/p/53266 ...
- vijosP1371 方程的解
vijosP1371 方程的解 链接:https://vijos.org/p/1371 [思路] 组合公式+快速幂+高精单精. 求x^x %1000:因为x最大为2^31-1所以用快速幂在O(logx ...