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的 ...
随机推荐
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow(flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter)
一. 1.Wiring a flow executor <flow:flow-executor id="flowExecutor" /> Although the fl ...
- bzoj2565
网络流就先告一段落了 在进行其他训练之前,我决定先练一道后缀数组(对这个我还是比较有自信的) 虽然之前没用后缀数组解决过回文问题,但是稍微想想就知道, 要解决最长双倍回文,首先要解决最长回文序列, 要 ...
- WordPress FunCaptcha插件跨站脚本漏洞
漏洞名称: WordPress FunCaptcha插件跨站脚本漏洞 CNNVD编号: CNNVD-201311-431 发布时间: 2013-11-29 更新时间: 2013-11-29 危害等级: ...
- WMS
Web地图位置服务 Web地图服务(Web map service)利用具有地理空间位置信息的数据制作地图.其中将地图定义为地理数据可视的表现.这个规范定义了三个操作:GetCapabitities返 ...
- nyoj 括号匹配
这个方程有两种形式,本文采用 if(s[i]=s[j]) dp[i][j]=d[i-1][j-1] dp[i][j]=min(dp[i][k]+dp[k+1][j],dp[i][j]) (i=&l ...
- 浏览器兼容性的css hack 写法
IE各版本浏览器之间的识别概括如下: IE6:能识别 * .\9 和 _ ,不能识别 !important IE7:能识别 * .\9 和 !important,不能识别 _ IE8:能识别 \9 和 ...
- HW2.12
控制台: import java.util.Scanner; public class Solution { public static void main(String[] args) { Scan ...
- HW2.5
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 常用apt cli
常用的APT命令参数: apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt-get ...
- Stream消息流 和 Stream Grouping 消息流组