知识大全 回收InnoDB表空间

Posted 空间

篇首语:坚志而勇为,谓之刚。刚,生人之德也。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 回收InnoDB表空间相关的知识,希望对你有一定的参考价值。

回收InnoDB表空间  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  以下论述均假定innodb_file_per_table开启

  先用常规optimize回收

  [plain]

  <pre name= code class= plain >mysql> select count(*) from t;

  + +

  | count(*) |

  + +

  |  |

  + +

  [mysql@even employees]$ ls alh t ibd

   rw rw mysql dba M : t ibd

  mysql> delete from t limit ;

  mysql> select count(*) from t;

  + +

  | count(*) |

  + +

  |   |

  + +

  [mysql@even employees]$ ls alh t ibd

   rw rw mysql dba M : t ibd

  mysql> optimize table t;

  + + + + +

  | Table       | Op       | Msg_type | Msg_text                                                          |

  + + + + +

  | employees t | optimize | note     | Table does not support optimize doing recreate + analyze instead |

  | employees t | optimize | status   | OK                                                                |

  + + + + +

  [mysql@even employees]$ ls alh t ibd

   rw rw mysql dba M : t ibd</pre><br><br>

  来看下这种方法的缺陷

  [plain]

  mysql> show processlist;

  + + + + + + + + +

  | Id | User | Host      | db        | Command | Time | State             | Info             |

  + + + + + + + + +

  |  | root | localhost | NULL      | Query   |    | NULL              | show processlist |

  |  | root | localhost | employees | Query   |   | copy to tmp table | optimize table t |

  + + + + + + + + +

  mysqladmin debug结果如下

  [plain]

  Thread database table_name          Locked/Waiting        Lock_type

          employees t                 Locked read         Read lock without concurrent inserts

  用optimize缺点显而易见 读锁 特别当你有大表时性能恐怕会深受影响

  这里推荐使用percona公司 pt online schema change 避免加锁

  [plain]

  $ pt online schema change uroot poracle alter ENGINE=InnoDB D=employees t=t execute

  执行pt工具时有可能发生的类似错误

  [plain]

  Cannot chunk the original table  There is no good index and the table is oversized

cha138/Article/program/MySQL/201311/29468

相关参考