root@db 15:46: [aaaa]> select count(*) from optimize_tb; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.28 sec)
查看文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 15:44 optimize_tb.frm -rw-r-----. 1 mysql mysql 48M 11月 27 15:46 optimize_tb.ibd
root@db 15:47: [aaaa]> select count(*) from optimize_tb; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.11 sec)
查看数据文件没有任何变化
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 15:44 optimize_tb.frm -rw-r-----. 1 mysql mysql 48M 11月 27 15:47 optimize_tb.ibd
session1执行优化表操作
1 2 3 4 5 6 7 8
root@db 15:48: [aaaa]> optimize table optimize_tb; +------------------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +------------------+----------+----------+-------------------------------------------------------------------+ | aaaa.optimize_tb | optimize | note | Table does not support optimize, doing recreate + analyze instead | | aaaa.optimize_tb | optimize | status | OK | +------------------+----------+----------+-------------------------------------------------------------------+ 2 rows in set (16.34 sec)
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 15:48 optimize_tb.frm -rw-r-----. 1 mysql mysql 28M 11月 27 15:48 optimize_tb.ibd
root@db 15:53: [aaaa]> alter table optimize_tb1 drop primary key; ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
root@db 15:56: [aaaa]> select count(*) from optimize_tb1; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.48 sec)
创建fulltext 索引
1 2 3
root@db 15:56: [aaaa]> create fulltext index name_fullind on optimize_tb1(name); Query OK, 0 rows affected, 1 warning (1 min 12.58 sec) Records: 0 Duplicates: 0 Warnings: 1
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 15:56 optimize_tb1.frm -rw-r-----. 1 mysql mysql 92M 11月 27 15:58 optimize_tb1.ibd
删除前50万数据
1 2 3 4 5 6 7 8 9 10
root@db 15:58: [aaaa]> delete from optimize_tb1 limit 500000; Query OK, 500000 rows affected (1 min 13.37 sec)
root@db 15:59: [aaaa]> select count(*) from optimize_tb1; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.50 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 15:56 optimize_tb1.frm -rw-r-----. 1 mysql mysql 92M 11月 27 15:59 optimize_tb1.ibd
session1对表进行优化
1 2 3 4 5 6 7 8
root@db 15:59: [aaaa]> optimize table optimize_tb1; +-------------------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +-------------------+----------+----------+-------------------------------------------------------------------+ | aaaa.optimize_tb1 | optimize | note | Table does not support optimize, doing recreate + analyze instead | | aaaa.optimize_tb1 | optimize | status | OK | +-------------------+----------+----------+-------------------------------------------------------------------+ 2 rows in set (1 min 13.65 sec)
root@db 16:00: [(none)]> show processlist; +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ | 5 | root | localhost | aaaa | Query | 41 | copy to tmp table | optimize table optimize_tb1 | | 7 | root | localhost | aaaa | Query | 40 | Waiting for table metadata lock | insert into optimize_tb1(id,name,age) values(8166638,'lucy1',24) | | 8 | root | localhost | NULL | Query | 0 | starting | show processlist | +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ 3 rows in set (0.00 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:00 optimize_tb1.frm -rw-r-----. 1 mysql mysql 48M 11月 27 16:02 optimize_tb1.ibd
root@db 16:06: [aaaa]> root@db 16:07: [aaaa]> select count(*) from optimize_tb2; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.41 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb2 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:04 optimize_tb2.frm -rw-r-----. 1 mysql mysql 56M 11月 27 16:06 optimize_tb2.ibd
root@db 16:11: [aaaa]> select count(*) from optimize_tb2; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.29 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb2 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:04 optimize_tb2.frm -rw-r-----. 1 mysql mysql 56M 11月 27 16:11 optimize_tb2.ibd
session1对表进行优化
1 2 3 4 5 6 7 8
root@db 16:11: [aaaa]> optimize table optimize_tb2; +-------------------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +-------------------+----------+----------+-------------------------------------------------------------------+ | aaaa.optimize_tb2 | optimize | note | Table does not support optimize, doing recreate + analyze instead | | aaaa.optimize_tb2 | optimize | status | OK | +-------------------+----------+----------+-------------------------------------------------------------------+ 2 rows in set (22.04 sec
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb2 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:11 optimize_tb2.frm -rw-r-----. 1 mysql mysql 32M 11月 27 16:12 optimize_tb2.ibd
root@db 16:25: [aaaa]> select count(*) from optimize_tb; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.25 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:23 optimize_tb.frm -rw-r-----. 1 mysql mysql 48M 11月 27 16:24 optimize_tb.ibd
root@db 16:26: [aaaa]> select count(*) from optimize_tb; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.13 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:23 optimize_tb.frm -rw-r-----. 1 mysql mysql 48M 11月 27 16:26 optimize_tb.ibd
root@db 16:27: [(none)]> show processlist; +----+------+-----------+------+---------+------+---------------------------------+-----------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+---------------------------------+-----------------------------------------------------------------+ | 2 | root | localhost | aaaa | Query | 19 | copy to tmp table | optimize table optimize_tb | | 3 | root | localhost | aaaa | Query | 11 | Waiting for table metadata lock | insert into optimize_tb(id,name,age) values(8166638,'lucy1',24) | | 4 | root | localhost | NULL | Query | 0 | starting | show processlist | +----+------+-----------+------+---------+------+---------------------------------+-----------------------------------------------------------------+
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:27 optimize_tb.frm -rw-r-----. 1 mysql mysql 28M 11月 27 16:27 optimize_tb.ibd
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:33 optimize_tb1.frm -rw-r-----. 1 mysql mysql 92M 11月 27 16:34 optimize_tb1.ibd
root@db 16:35: [aaaa]> select count(*) from optimize_tb1; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.69 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:33 optimize_tb1.frm -rw-r-----. 1 mysql mysql 92M 11月 27 16:36 optimize_tb1.ibd
root@db 16:37: [(none)]> show processlist; +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ | 2 | root | localhost | aaaa | Query | 9 | copy to tmp table | optimize table optimize_tb1 | | 4 | root | localhost | NULL | Query | 0 | starting | show processlist | | 5 | root | localhost | aaaa | Query | 8 | Waiting for table metadata lock | insert into optimize_tb1(id,name,age) values(8166638,'lucy1',24) | +----+------+-----------+------+---------+------+---------------------------------+------------------------------------------------------------------+ 3 rows in set (0.00 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb1 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:37 optimize_tb1.frm -rw-r-----. 1 mysql mysql 48M 11月 27 16:38 optimize_tb1.ibd
root@db 16:41: [aaaa]> select count(*) from optimize_tb2; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.49 sec)
查看数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb2 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:40 optimize_tb2.frm -rw-r-----. 1 mysql mysql 56M 11月 27 16:41 optimize_tb2.ibd
root@db 16:42: [aaaa]> select count(*) from optimize_tb2; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.32 sec)
数据文件大小
1 2 3
[root@dax-mysql-master aaaa]# ls -lhtr|grep optimize_tb2 -rw-r-----. 1 mysql mysql 8.5K 11月 27 16:40 optimize_tb2.frm -rw-r-----. 1 mysql mysql 56M 11月 27 16:42 optimize_tb2.ibd