文系プログラマによるTIPSブログ

文系プログラマ脳の私が開発現場で学んだ事やプログラミングのTIPSをまとめています。

Error: Table "mysql"."innodb_table_stats" not found.のバグに対応する

MySQLにもバグはあるのです〜


f:id:treeapps:20180418131549p:plain

mysql5.6で、error.logに以下のログが出力される事があります。

2014-08-25 12:52:43 7f1c8e330700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2014-08-25 12:52:43 7f1c8e330700 InnoDB: Recalculation of persistent statistics requested for table "test"."hoge" but the required persistent statistics storage is not present or is corrupted. Using transient stats instead.

恐らく以下のバグであると思われます。
MySQL Bugs: #67179: mysql system tables innodb_table_stats,slave_master_info not accessible on clean

私の場合はyumでインストールしたMySQL5.6がこのバグを含んでいました。
RDSの場合は問題ありません。

このバグは以下のSQLで直ります。
http://bugs.mysql.com/file.php?id=19725&bug_id=67179&text=1

一応修正フローを説明すると、以下の順に操作します。

  • rootでログインする。
  • use mysqlする。
  • drop table innodb_index_stats;
  • drop table innodb_table_stats;
  • drop table slave_master_info;
  • drop table slave_relay_log_info;
  • drop table slave_worker_info;
  • cd /var/lib/mysql/mysql にある ↑のテーブルの .frm と .ibd を以下のように削除する。
    • rm -rf innodb_index_stats*
    • rm -rf innodb_table_stats*
    • rm -rf slave_master_info*
    • rm -rf slave_relay_log_info*
    • rm -rf slave_worker_info*
  • 前述のsqlをmysqlスキーマに対して実行し、テーブルを新規に作成する。
  • mysqlのサービスを再起動する。

これで直ります!