MySQL で破損した DB のテーブルを修復する






MySQL で破損した DB のテーブルを修復する方法は以下の通り。

OS が Linux でも Windows でも同じ。
コマンドで設定する。

例は、cacti で使っている DB 。

# mysql -u [ユーザ名] -p
Enter password:[パスワード]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 91300
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use cacti
Database changed
mysql> 
mysql> show tables;
+--------------------------------+
| Tables_in_cacti                |
+--------------------------------+
| cdef                           |
| cdef_items                     |
| colors                         |
| data_input                     |
| data_input_data                |
| data_input_fields              |
| data_local                     |
| data_template                  |
| data_template_data             |
| data_template_data_rra         |
| data_template_rrd              |
| graph_local                    |
| graph_template_input           |
| graph_template_input_defs      |
| graph_templates                |
| graph_templates_gprint         |
| graph_templates_graph          |
| graph_templates_item           |
| graph_tree                     |
| graph_tree_items               |
| host                           |
| host_graph                     |
| host_snmp_cache                |
| host_snmp_query                |
| host_template                  |
| host_template_graph            |
| host_template_snmp_query       |
| plugin_config                  |
| plugin_db_changes              |
| plugin_hooks                   |
| plugin_notification_lists      |
| plugin_realms                  |
| plugin_thold_contacts          |
| plugin_thold_host_failed       |
| plugin_thold_log               |
| plugin_thold_template_contact  |
| plugin_thold_threshold_contact |
| poller                         |
| poller_command                 |
| poller_item                    |
| poller_output                  |
| poller_output_boost            |
| poller_output_boost_processes  |
| poller_reindex                 |
| poller_time                    |
| rra                            |
| rra_cf                         |
| settings                       |
| settings_graphs                |
| settings_tree                  |
| snmp_query                     |
| snmp_query_graph               |
| snmp_query_graph_rrd           |
| snmp_query_graph_rrd_sv        |
| snmp_query_graph_sv            |
| thold_data                     |
| thold_template                 |
| user_auth                      |
| user_auth_perms                |
| user_auth_realm                |
| user_log                       |
| version                        |
| weathermap_auth                |
| weathermap_data                |
| weathermap_groups              |
| weathermap_maps                |
| weathermap_settings            |
+--------------------------------+
67 rows in set (0.00 sec)

mysql> check table settings;
+----------------+-------+----------+----------+
| Table          | Op    | Msg_type | Msg_text |
+----------------+-------+----------+----------+
| cacti.settings | check | status   | OK       |
+----------------+-------+----------+----------+
1 row in set (0.03 sec)


Msg_type が、error や warning になっている場合、破損している。

破損した DB のテーブルは以下のコマンドで修復する。


mysql> repair table [テーブル名];