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的更多相关文章

  1. OPTIMIZE TABLE 小解

    首先看一下语法:  OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [, tbl_name] ... 我们知道mysql存储引擎里面的数据和索 ...

  2. 使用 SQL 命令 OPTIMIZE TABLE 释放表空间

    前提: 1.删除了表的一大部分: 2.已经对含有可变长度行的表(含有VARCHAR, BLOB或TEXT列的表)进行了很多更改. ----------------------------------- ...

  3. mysql下优化表和修复表命令使用说明(REPAIR TABLE和OPTIMIZE TABLE)

    随着mysql的长期使用,可以修复表来优化,优化时减少磁盘占用空间.方便备份. REPAIR TABLE `table_name` 修复表 OPTIMIZE TABLE `table_name` 优化 ...

  4. mysql中OPTIMIZE TABLE的作用

    在使用mysql的时候有时候,可能会发现尽管一张表删除了许多数据,但是这张表表的数据文件和索引文件却奇怪的没有变小.这是因为mysql在删除数据(特别是有Text和BLOB)的时候,会留下许多的数据空 ...

  5. OPTIMIZE TABLE的作用--转载

    当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删 除操作后在数据文件中留下碎片所致.Discuz! 在系统数设置界面提供了数据表优化的功能,可以去除删除操作后留下的数据文件 ...

  6. optimize table table_name myisam mysql自动清除删除过留下的空记录

    optimize table table_name 这个可以清除你表里面的空记录,每次清除的时候记得锁表 lock tables table_name  write|read; unlock tabl ...

  7. 使用OPTIMIZE TABLE命令来整理表碎片实践

    操作环境:ubuntu 14.10   mysql 5.6.25 对含有BLOB或TEXT字段的表,若经常做修改或删除类的操作,需要定期执行OPTIMIZE TABLE命令来整理碎片. 1.creat ...

  8. optimize table 表优化问题

    语法: optimize table '表名' 一,原始数据 1,数据量 2,存放在硬盘中的表文件大小 3,查看一下索引信息 索引信息中的列的信息说明. Table :表的名称.Non_unique: ...

  9. 实例说明optimize table在优化MySQL时很重要

    今天在看CU的时候,发现有人问有关optimize来表优化的问题,当年因为这个问题,困扰我很长一段时间,今天有空我把这个问题,用实际数据来展示出来,让大家可以亲眼来看看,optimize table的 ...

随机推荐

  1. Android 设置控件可见与不可见

    通常控件的可见与不可见分为三种情况 第一种    gone         表示不可见并且不占用空间 第二种    visible       表示可见 第三种    invisible    表示不 ...

  2. linux如何安装jdk

    一.安装 创建安装目录,在/usr/java下建立安装路径,并将文件考到该路径下: # mkdir /usr/java 1.jdk-6u11-linux-i586.bin 这个是自解压的文件,在lin ...

  3. MySQL学习笔记之一

    MySQL装有一个名为mysql的命令行,在提示符下输入mysql将出现如下的简单提示: ➜ ~ mysql Welcome to the MySQL monitor. Commands end wi ...

  4. HashMap与HashTable联系与区别

    HashMap与HashTable 1.hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法. 2.hashTabl ...

  5. leetcode面试准备: Maximal Rectangle

    leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...

  6. iOS上获得MAC地址

    很多时候我们都需要唯一来确定一台设备,苹果设备本来有个UDID号,可以实现这个目的.在iOS5.0以前,还有一个uniqueIdentifier的API用来获得这个number.不过iOS5之后,这个 ...

  7. 【HDOJ】3337 Guess the number

    神一样的题目.简言之,利用手段获得测试用例的第一行,输出结果.很显然利用wa, TLE, OLE等judge status可以获得测试用例.因此,果断Python写一个acm提交机器人.依赖lxml库 ...

  8. BZOJ_1221_ [HNOI2001]_软件开发(最小费用流,网络流24题#10)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1221 n天,每天需要r个毛巾,用完以后可以洗,要么花fa洗a天,要么花fb洗b天,毛巾不够了可 ...

  9. [HDU 4549] M斐波那契数列

    M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  10. 【转】Ubuntu下配置支持Windows访问的samba共享

    原文网址:http://blog.csdn.net/i_chips/article/details/19191957 一.安装Ubuntu samba服务器 $ sudo apt-get instal ...