Quantcast
Channel: Tech Tips – All Systems GO
Viewing all articles
Browse latest Browse all 3

How to Fix MySQL 5.6.x corrupt innodb_table_stats and slave_master_* Tables

$
0
0

In version 5.6 of MySQL, you might get errors regarding InnoDB tables mysql/innodb_table_stats, mysql/slave_master_info,mysql/slave_worker_info, and mysql/slave_relay_log_info  like the following when the server was not gracefully shut down, and the InnoDB tables in question become eventually corrupt. This article will present detailed instructions to fix the problem.

The Error in Scope


2018-01-30 01:11:53 2060 [Note] InnoDB: 5.6.35 started; log sequence number 11971357
2018-01-30 01:11:53 2060 [Note] RSA private key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//private_key.pem. Some authentication plugins will not work.
2018-01-30 01:11:53 2060 [Note] RSA public key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//public_key.pem. Some authentication plugins will not work.
2018-01-30 01:11:53 2060 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2018-01-30 01:11:53 2060 [Note] - '127.0.0.1' resolves to '127.0.0.1';
2018-01-30 01:11:53 2060 [Note] Server socket created on IP: '127.0.0.1'.
2018-01-30 01:11:53 2060 [Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists.
2018-01-30 01:11:53 2060 [Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.
2018-01-30 01:11:53 2060 [Warning] InnoDB: Cannot open table mysql/slave_worker_info from the internal data dictionary of InnoDB though the .frm file for the table exists.
2018-01-30 01:11:53 2060 [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-30 01:11:53 2060 [Warning] Info table is not ready to be used. Table 'mysql.slave_relay_log_info' cannot be opened.

Furthermore the following additional errors can be found in mysql_error.log:

2018-01-30 01:12:45 70000caaf000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2018-01-30 01:12:45 70000caaf000 InnoDB: Error: Fetch of persistent statistics requested for table "sakila"."actors" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.

You could even get a hint for a resolution at the end of one of the above error messages in the log pointing to the URL: http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html, however the explanations on the web page are somewhat superficial. However, the below instructions will shed light for a more clear action plan:

Solution to Fix the Corrupt InnoDB Tables

In order to rebuild the tables, you may need to enable the “force recovery” option when starting MySQL which is disabled by default. To enable “force recovery”, add the following in your MySQL configuration file (in my case it is my.cnf but yours could be my.ini).

[mysqld]
innodb_force_recovery = 1

And restart MySQL server.

After performing the above, my innodb_table_stats table problem seems to have been fixed, but I’m still getting the same errors regarding slave_master_info, slave_worker_info and slave_relay_log_info:


2018-01-30 10:41:44 8691 [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-30 10:41:44 8691 [Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.
2018-01-30 10:41:44 8691 [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.
2018-01-30 10:41:44 8691 [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-30 10:41:44 8691 [Warning] Info table is not ready to be used. Table 'mysql.slave_relay_log_info' cannot be opened.

Rebuilding the InnoDB Tables

  1. Drop the following tables from mysql schema:
    • innodb_index_stats
    • innodb_table_stats
    • slave_master_info
    • slave_relay_log_info
    • slave_worker_info

    You could use this query for it:

    DROP TABLE IF EXISTS `innodb_index_stats`;
    DROP TABLE IF EXISTS `innodb_table_stats`;
    DROP TABLE IF EXISTS `slave_master_info`;
    DROP TABLE IF EXISTS `slave_relay_log_info`;
    DROP TABLE IF EXISTS `slave_worker_info`;
  2. Delete *.frm and *.ibd files of the above tables from the file system.
  3. Re-create the tables by running the following queries:MySQL query to rebuild corrupt InnoDB tables
    CREATE TABLE IF NOT EXISTS `innodb_index_stats` (
    `database_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `table_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `index_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `stat_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `stat_value` bigint(20) unsigned NOT NULL,
    `sample_size` bigint(20) unsigned DEFAULT NULL,
    `stat_description` varchar(1024) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`database_name`,`table_name`,`index_name`,`stat_name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;
    
    CREATE TABLE IF NOT EXISTS `innodb_table_stats` (
    `database_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `table_name` varchar(64) COLLATE utf8_bin NOT NULL,
    `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `n_rows` bigint(20) unsigned NOT NULL,
    `clustered_index_size` bigint(20) unsigned NOT NULL,
    `sum_of_other_index_sizes` bigint(20) unsigned NOT NULL,
    PRIMARY KEY (`database_name`,`table_name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;
    
    CREATE TABLE IF NOT EXISTS `slave_master_info` (
    `Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file.',
    `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.',
    `Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last read event.',
    `Host` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'The host name of the master.',
    `User_name` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The user name used to connect to the master.',
    `User_password` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The password used to connect to the master.',
    `Port` int(10) unsigned NOT NULL COMMENT 'The network port used to connect to the master.',
    `Connect_retry` int(10) unsigned NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.',
    `Enabled_ssl` tinyint(1) NOT NULL COMMENT 'Indicates whether the server supports SSL connections.',
    `Ssl_ca` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.',
    `Ssl_capath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path to the Certificate Authority (CA) certificates.',
    `Ssl_cert` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL certificate file.',
    `Ssl_cipher` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the cipher in use for the SSL connection.',
    `Ssl_key` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL key file.',
    `Ssl_verify_server_cert` tinyint(1) NOT NULL COMMENT 'Whether to verify the server certificate.',
    `Heartbeat` float NOT NULL,
    `Bind` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server',
    `Ignored_server_ids` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs',
    `Uuid` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The master server uuid.',
    `Retry_count` bigint(20) unsigned NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.',
    `Ssl_crl` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Revocation List (CRL)',
    `Ssl_crlpath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path used for Certificate Revocation List (CRL) files',
    `Enabled_auto_position` tinyint(1) NOT NULL COMMENT 'Indicates whether GTIDs will be used to retrieve events from the master.',
    PRIMARY KEY (`Host`,`Port`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Master Information';
    
    CREATE TABLE IF NOT EXISTS `slave_relay_log_info` (
    `Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.',
    `Relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the current relay log file.',
    `Relay_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The relay log position of the last executed event.',
    `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.',
    `Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last executed event.',
    `Sql_delay` int(11) NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.',
    `Number_of_workers` int(10) unsigned NOT NULL,
    `Id` int(10) unsigned NOT NULL COMMENT 'Internal Id that uniquely identifies this record.',
    PRIMARY KEY (`Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Relay Log Information';
    
    CREATE TABLE IF NOT EXISTS `slave_worker_info` (
    `Id` int(10) unsigned NOT NULL,
    `Relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `Relay_log_pos` bigint(20) unsigned NOT NULL,
    `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `Master_log_pos` bigint(20) unsigned NOT NULL,
    `Checkpoint_relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `Checkpoint_relay_log_pos` bigint(20) unsigned NOT NULL,
    `Checkpoint_master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `Checkpoint_master_log_pos` bigint(20) unsigned NOT NULL,
    `Checkpoint_seqno` int(10) unsigned NOT NULL,
    `Checkpoint_group_size` int(10) unsigned NOT NULL,
    `Checkpoint_group_bitmap` blob NOT NULL,
    PRIMARY KEY (`Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Worker Information';
  4. Restart MySQL.

Viewing all articles
Browse latest Browse all 3

Trending Articles