1. 程式人生 > >Mysql 5.7.20 mysql innodb 系統表損壞帶來的問題

Mysql 5.7.20 mysql innodb 系統表損壞帶來的問題

sha use linux系統 type log tle blob b- 資料

早上上班後,mysql服務器遇到點小問題,在排查故障過程查看mysql錯誤日誌過程中發現有幾個innodb 表無法打開,使用desc查看有關表的表結構提示表不存在,show tables 可以查到一下五個表,以下是具體的報錯信息:

2018-01-12 09:17:41 17235 [Warning] InnoDB: Cannot open table mysql/innodb_index_stats from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

2018-01-12 09:17:41 17235 [Warning] InnoDB: Cannot open table mysql/innodb_table_stats from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

2018-01-12 09:17:41 17235 [Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

2018-01-12 09:17:41 17235 [Warning] InnoDB: Cannot open table mysql/slave_relay_log_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

2018-01-12 09:17:41 17235 [Warning] InnoDB: Cannot open table mysql/slave_worker_info from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

網上查了下資料,問題的問題產生原因:數據庫打開這幾張表的默認引擎為MyISAM,但是這幾張表在建表時的引擎為INNODB;從而引起mysql報錯

msyql在5.6版本引入了以下五個表

innodb_index_stats,

innodb_tables_stats,

slave_master_info,

slave_relay_log_info,

slave_worker_info

定位了問題原因後,那我們就開始著手準備解決以上存在的問題,解決的思路是,刪除有問題的表和數據文件,使用安裝msyql的官方自帶建表腳本,重新創建有問題的5個表。

操作步驟如下

1,登錄數據庫執行以下操作,sql語句加if 判斷,如果表存在,則刪除

mysql> use mysql;

mysql> drop table if exists innodb_index_stats;

mysql> drop table if exists innodb_table_stats;

mysql> drop table if exists slave_master_info;

mysql> drop table if exists slave_relay_log_info;

mysql> drop table if exists slave_worker_info;

mysql> show tables; 驗證執行結果,以上表是否已刪除

2,停止mysql數據庫服務,並進入到數據庫數據文件所在目錄,刪除上面5個表所對應的idb文件,linux系統環境,我的msyql的basedir目錄是 /usr/local/mysql/

datadir目錄是/data/mysql/var/mysql/

[root@mysql5 ]# systemctl restart stop

[root@sql5 root]# cd /data/mysql/var/mysql/

[root@sql5 mysql]# ls -l *.ibd

-rw-rw---- 1 mysql mysql 98304 37 2017 innodb_index_stats.ibd

-rw-rw---- 1 mysql mysql 98304 37 2017 innodb_table_stats.ibd

-rw-rw---- 1 mysql mysql 98304 37 2017 slave_master_info.ibd

-rw-rw---- 1 mysql mysql 98304 37 2017 slave_relay_log_info.ibd

-rw-rw---- 1 mysql mysql 98304 37 2017 slave_worker_info.ibd

[root@sql5 mysql]#rm -rf *.ibd

3,重啟mysql服務,並重建被刪除的五個表的表結構,建表腳本在mysql軟件的安裝目錄的share目錄下或者mysql的安裝包的script目錄下

[root@mysql5 mysql]# cd /usr/local/mysql/share/

[root@mysql5 share]# ls -l *.sql //查看所有的建表腳本

-rw-r--r--. 1 root root 932622 913 23:56 fill_help_tables.sql

-rw-r--r--. 1 root root 3999 913 23:48 innodb_memcached_config.sql

-rw-r--r--. 1 root root 1812 117 11:42 install_rewriter.sql

-rw-r--r--. 1 root root 1760 913 23:48 mysql_security_commands.sql

-rw-r--r--. 1 root root 287110 913 23:48 mysql_sys_schema.sql

-rw-r--r--. 1 root root 811 913 23:48 mysql_system_tables_data.sql

-rw-r--r--. 1 root root 154624 913 23:48 mysql_system_tables.sql

-rw-r--r--. 1 root root 10410 913 23:48 mysql_test_data_timezone.sql

-rw-r--r--. 1 root root 834 117 11:42 uninstall_rewriter.sql

[root@mysql5 share]# systemctl restart mysqld

mysql> USE MYSQL;

mysql> source /usr/local/mysql/share/innodb_memcached_config.sql

mysql> show tables; 刪除的5個表已恢復

技術分享圖片

mysql> DESC innodb_table_stats ;

技術分享圖片

其余四個表結構的查看過程略,

在查看mysql的錯誤日誌,報錯信息沒有了

[root@mysql5 share]# tail /data/mysql/var/mysqld.err

技術分享圖片


Mysql 5.7.20 mysql innodb 系統表損壞帶來的問題