码迷,mamicode.com
首页 > 其他好文 > 详细

OPTIMIZE TABLE

时间:2016-07-03 00:15:15      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

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)

 

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

标签:

原文地址:http://www.cnblogs.com/zengkefu/p/5636220.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!