'mysql.innodb_index_stats' doesn't exist when using LOCK TABLES问题原因及解决方法

news/2024/7/7 7:36:42

前言


下面总结的是使用mysqldump备份整个数据库时的常见的一个报错的原因及解决方法。




报错如下


mysqldump: Got error: 1146: Table ‘mysql.innodb_index_stats’ doesn’t exist when using LOCK TABLES


执行导出数据库时报1146,mysql_innodb_table_stats显示没有这个表

在这里插入图片描述

接着进入,创建此表的时候,报错1813提示,表已存在
在这里插入图片描述




问题原因及解决方法



原因


由于在数据库初始化的时候,删除过ibdata1文件,而数据库虽然重启后新生成了ibdata1,但innodb引擎并没有使用新的共享表空间ibdata1导致。



解决方法



【1】关闭mysql操作及停止mysql服务



【2】删除系统表或删除数据目录内同名表文件



<1>进入数据库中,执行命令
(如报错1813,执行第2个操作)

drop table mysql.innodb_index_stats;
drop table mysql.innodb_table_stats;
drop table mysql.slave_master_info;
drop table mysql.slave_relay_log_info;
drop table mysql.slave_worker_info;


<2>删除你的mysql的数据目录下相关的文件
(通常是与表同名的文件)

例如:cd /apk/data/mysql_3306/data/mysql

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*


<3>重启数据库

systemctl restart mysqld
or 
/etc/init.d/mysqld restart


【3】登录数据库,创建缺失的系统表


use mysql; 

CREATE TABLE `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 `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 `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 `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 `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';



补充


如上述的操作是在主从的结构中执行,导致主从连接失败,数据相差不大时,重新配置主从即可,无需导入数据。
https://blog.csdn.net/GX_1_11_real/article/details/81237626

其他的1146问题解决方法,可查看下列链接:
https://blog.csdn.net/GX_1_11_real/article/details/81347343


http://www.niftyadmin.cn/n/3585849.html

相关文章

数据Cocos2d-x常用功能-Cocos2d-x常用工具:计时器、数据读写、文件读写(共6部分)

第三阶段&#xff1a;常用功能5 1.Cocos2d-x计时器每一帧执行的时候执行一次#include "cocos2d.h"class HelloWorld : public cocos2d::Layer { private: cocos2d::LabelTTF *label; public: // theres no id in cpp, so we recommend returning…

lvs架构

lvs 4种模式 1、nat(网络地址转换模式) 2、dr(直接路由模式) 3、tun(隧道模式) 4、full-nat(双向转换模式) 1&#xff0c;nat&#xff08;网络地址转换模式架构&#xff09; 1、nat模式优势是&#xff0c;后端可以是任意支持tcp/ip的操作系统&#xff0c;缺点是响应时回包必须…

容器:用empty来代替检查size()是否为0

对于任意容器c&#xff0c;写下 if (c.size() 0)... 本质上等价于写下 if (c.empty())... 这就是例子。你可能会奇怪为什么一个构造会比另一个好&#xff0c;特别是事实上empty的典型实现是一个返回size是否返回0的内联函数。 你应该首选empty的构造&#xff0c;而且理由很…

nginx 代理 负载均衡 网站转接的用法

反向代理 1&#xff0c;准备两台nginx真实服务器 a、nginx-1 启动网站(内容)&#xff08;作为网站服务器&#xff09; b、nginx-2 启动代理程序 一、编辑nginx-2的配置文件 [rootnginx-server ~]# vim /etc/nginx/conf.d/default.conf server {server {listen 80; ser…

LNMP+zabbix监控平台搭建

前言 由于某个项目需要新搭建zabbix监控平台。于是就抽时间总结了zabbix搭建的流程及排错的详细流程。由于每个人的生产环境的差异&#xff0c;本文适用于参考。 实际上&#xff0c;使用yum安装配置LAMPzabbix更加的方便&#xff0c;快捷。但是&#xff0c;为了便于管理&#…

PHP生成图像验证码的方法小结(2种方法)

本文实例讲述了PHP生成图像验证码的方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a; 1、生成加法运算验证码图片 ?123456789101112131415161718192021222324252627282930session_start ();/*定义头文件为图片*/header("Content-type: image/png");/*生…

尽量使用区间成员函数代替它们的单元素兄弟

尽量使用区间成员函数来代替单元素兄弟的三个可靠的论点&#xff1a; 1、区间成员函数更容易写&#xff0c; 2、它们更清楚地表达你的意图&#xff0c; 3、而且它们提供了更高的性能。 快&#xff01;给定两个vector&#xff0c;v1和v2&#xff0c;使v1的内容和v2的后半部分…

源码安装软件参数查询

前言 下面总结的是对部分已源码安装的软件&#xff0c;查看其编译参数的方法。 常用于软件升级或安装扩展模块 【1】Nginx 编译参数查询 命令&#xff1a; /apk/install/nginx/sbin/nginx -V注意&#xff1a;nginx命令位置取决于nginx的安装目录 nginx version: nginx/1.17.1 …