删除一些行后如何优化MySQL表?
使用OPTIMIZE TABLE命令优化MySQL表-
optimize table yourTableName;
让我们首先创建一个表-
mysql> create table DemoTable(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name varchar(100)
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Name) values('Chris');mysql> insert into DemoTable(Name) values('Robert');
mysql> insert into DemoTable(Name) values('Bob');
mysql> insert into DemoTable(Name) values('David');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+--------+| Id | Name |
+----+--------+
| 1 | Chris |
| 2 | Robert |
| 3 | Bob |
| 4 | David |
+----+--------+
4 rows in set (0.00 sec)
现在让我们从表中删除行-
mysql> delete from DemoTable where Id IN(1,3);mysql> select *from DemoTable;
+----+--------+
| Id | Name |
+----+--------+
| 2 | Robert |
| 4 | David |
+----+--------+
2 rows in set (0.00 sec)
以下是优化上面和删除一些行后创建的表的查询-
mysql> optimize table DemoTable;
这将产生以下输出-
+------------------+----------+----------+-------------------------------------------------------------------+| Table | Op | Msg_type | Msg_text |
+------------------+----------+----------+-------------------------------------------------------------------+
| web.DemoTable | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| web.DemoTable | optimize | status | OK |
+------------------+----------+----------+-------------------------------------------------------------------+
2 rows in set (4.32 sec)
以上是 删除一些行后如何优化MySQL表? 的全部内容, 来源链接: utcz.com/z/316679.html