Is it safe to kill an OPTIMIZE query on an InnoDB table without corrupting the table?

The MySQL docs says:

However, killing a REPAIR TABLE or OPTIMIZE TABLE operation on a MyISAM table results in a table that is corrupted and is unusable (reads and writes to it fail) until you optimize or repair it again (without interruption).

But it doesn't say anything about InnoDB.

有帮助吗?

解决方案

If you OPTIMIZE InnoDB table it creates a new index structure for it and copies records from the old table to the new. When the copy is done it then switches the tables.

If you kill OPTIMIZE in the middle of this InnoDB will have to rollback.

It is safe, but it may take long time to rollback.

其他提示

In my case, an OPTIMIZE task was killed with mysql's kill command, but killing it did not stop the process. So sometimes even if you kill the task, it still stays.

> show processlist;

| Id    | User        | Host      | db                    | Command | Time | State                    | Info                                                                                                 | Progress |
+-------+-------------+-----------+-----------------------+---------+------+--------------------------+------------------------------------------------------------------------------------------------------+----------+
|     1 | system user |           | NULL                  | Daemon  | NULL | InnoDB purge coordinator | NULL                                                                                                 |    0.000 |
|     2 | system user |           | NULL                  | Daemon  | NULL | InnoDB purge worker      | NULL                                                                                                 |    0.000 |
|     3 | system user |           | NULL                  | Daemon  | NULL | InnoDB purge worker      | NULL                                                                                                 |    0.000 |
|     4 | system user |           | NULL                  | Daemon  | NULL | InnoDB purge worker      | NULL                                                                                                 |    0.000 |
|     5 | system user |           | NULL                  | Daemon  | NULL | InnoDB shutdown handler  | NULL                                                                                                 |    0.000 |
|   142 | admin       | localhost | tsa                   | Sleep   |   20 |                          | NULL                                                                                                 |    0.000 |
|  5114 | admin       | localhost | something_wp          | Killed  | 5419 | Parallel repair          | OPTIMIZE TABLE `wp_options` 

Although it says Killed, it stayed in the process list..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top