ibdata1文件损坏时恢复InnoDB单表测试
[root@zlm1 :: ~]
#innobackupex --defaults-file=/data/mysql/mysql3306/my3306.cnf --user=root --password=Passw0rd /data/backup
:: innobackupex: Starting the backup operation
... //Omitted. [root@zlm1 :: /data/backup]
#ls -l
total
drwxr-x--- root root Aug : --05_13-- [root@zlm1 :: /data/backup]
Check the target table which we want to rescue in plan.
zlm@192.168.56.100: [sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
+--------------------+
rows in set (0.00 sec) zlm@192.168.56.100: [sysbench]>select count(*) from sbtest4;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.05 sec) zlm@192.168.56.100: [sysbench]>delete from sbtest4 limit ;
Query OK, rows affected (0.17 sec) zlm@192.168.56.100: [sysbench]>select count(*) from sbtest4;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec)
Destroy the ibdata1 file with "dd" command.
[root@zlm1 :: ~]
#cd /data/mysql/mysql3306/data [root@zlm1 :: /data/mysql/mysql3306/data]
#ls -l
total
-rw-r----- mysql mysql Mar : auto.cnf
-rw-r----- mysql mysql Aug : error.log
-rw-r----- mysql mysql Jul : ib_buffer_pool
-rw-r----- mysql mysql Aug : ibdata1
-rw-r----- mysql mysql Aug : ib_logfile0
-rw-r----- mysql mysql Aug : ib_logfile1
-rw-r----- mysql mysql Jul : ib_logfile2
-rw-r----- mysql mysql Aug : ibtmp1
-rw-r----- mysql mysql Aug : innodb_status.
-rw-r----- mysql mysql Jul : innodb_status.
-rw-r----- mysql mysql Jun : innodb_status.
drwxr-x--- mysql mysql Jul : mrbs
drwxr-x--- mysql mysql Mar : mysql
-rw-r----- mysql mysql Aug : mysql.pid
drwxr-x--- mysql mysql Mar : performance_schema
-rw-r----- mysql mysql Jun : relay-bin.
-rw-r----- mysql mysql Jun : relay-bin.index
-rw-r----- mysql mysql Aug : slow.log
drwxr-x--- mysql mysql Mar : sys
drwxr-x--- mysql mysql Jul : sysbench
-rw-r----- mysql mysql Jul : zlm1.log [root@zlm1 :: /data/mysql/mysql3306/data]
#dd if=/dev/zero of=./ibdata1 bs= count=
+ records in
+ records out
bytes ( MB) copied, 1.61997 s, MB/s [root@zlm1 :: /data/mysql/mysql3306/data]
#ls -l|grep ibdata1
-rw-r----- mysql mysql Aug : ibdata1 //The ibdata1 turned out to be 256M and filled with zero.
Restart the MySQL instance.
zlm@192.168.56.100: [sysbench]>exit
Bye [root@zlm1 :: ~]
#mysqladmin shutdown [root@zlm1 :: ~]
#ps aux|grep mysqld
root 0.0 0.0 pts/ R+ : : grep --color=auto mysqld [root@zlm1 :: ~]
#./mysqld.sh [root@zlm1 :: ~]
#mysql
ERROR (HY000): Can't connect to MySQL server on '192.168.56.100' (111) [root@zlm1 :: ~]
#mysql
ERROR (HY000): Can't connect to MySQL server on '192.168.56.100' (111) [root@zlm1 :: ~]
#cd /data/mysql/mysql3306/data [root@zlm1 :: /data/mysql/mysql3306/data]
#tail error.log
... /Omitted.
--05T12::.242723Z [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
--05T12::.242806Z [Note] mysqld (mysqld 5.7.-log) starting as process ...
--05T12::.249168Z [Note] InnoDB: PUNCH HOLE support available
--05T12::.249207Z [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
--05T12::.249213Z [Note] InnoDB: Uses event mutexes
--05T12::.249218Z [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
--05T12::.249222Z [Note] InnoDB: Compressed tables use zlib 1.2.
--05T12::.249227Z [Note] InnoDB: Using Linux native AIO
--05T12::.249426Z [Note] InnoDB: Number of pools:
--05T12::.249507Z [Note] InnoDB: Using CPU crc32 instructions
--05T12::.251488Z [Note] InnoDB: Initializing buffer pool, total size = 100M, instances = , chunk size = 100M
--05T12::.256630Z [Note] InnoDB: Completed initialization of buffer pool
--05T12::.257913Z [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
--05T12::.280321Z [Note] InnoDB: Highest supported file format is Barracuda.
:: UTC - mysqld got signal ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail. key_buffer_size=
read_buffer_size=
max_used_connections=
max_threads=
thread_count=
connection_count=
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = K bytes of memory
Hope that's ok; if not, decrease some variables in the equation. Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = thread_stack 0x30000
mysqld(my_print_stacktrace+0x35)[0xf4a495]
mysqld(handle_fatal_signal+0x4a4)[0x7ce2f4]
/lib64/libpthread.so.(+0xf130)[0x7f6bbee76130]
mysqld(_Z26page_cur_search_with_matchPK11buf_block_tPK12dict_index_tPK8dtuple_t15page_cur_mode_tPmS9_P10page_cur_tP8rtr_info+0x148)[0x1074478]
mysqld(_Z27btr_cur_search_to_nth_levelP12dict_index_tmPK8dtuple_t15page_cur_mode_tmP9btr_cur_tmPKcmP5mtr_t+0x1598)[0x11806d8]
mysqld(_Z30btr_pcur_open_on_user_rec_funcP12dict_index_tPK8dtuple_t15page_cur_mode_tmP10btr_pcur_tPKcmP5mtr_t+0x212)[0x1184b62]
mysqld[0x11df28d]
mysqld(_Z19dict_load_sys_tableP12dict_table_t+0x69)[0x11e0609]
mysqld(_Z9dict_bootv+0xdfb)[0x11bf48b]
mysqld(_Z34innobase_start_or_create_for_mysqlv+0x3212)[0x11150a2]
mysqld[0x100023a]
mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x819721]
mysqld[0xd39226]
mysqld(_Z40plugin_register_builtin_and_init_core_sePiPPc+0x3e4)[0xd397a4]
mysqld[0x7c48f7]
mysqld(_Z11mysqld_mainiPPc+0x92f)[0x7c7e9f]
/lib64/libc.so.(__libc_start_main+0xf5)[0x7f6bbd857af5]
mysqld[0x7be479]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash. [root@zlm1 :: /data/mysql/mysql3306/data] //Okay,becasue of the lack of normal ibdata1 file in datadir,the instance cannot be started again.
//Then,how can we resuce the data in target table 'sbtest4'?
//First of all,let's get the ibd and frm file of it from the crashed server.
Copy ibd and frm file of table "sbtest4" to another newly initialized instance on zlm2.
[root@zlm1 :: /data/mysql/mysql3306/data/sysbench]
#scp sbtest4.* zlm2:/data/backup
sbtest4.frm % .4KB/s :
sbtest4.ibd % 10MB .0MB/s :
Install mysql-utilities package on zlm2.
[root@zlm2 :: ~]
#mysqlfrm --help
-bash: mysqlfrm: command not found [root@zlm2 :: ~]
#yum install mysql-utilities
Loaded plugins: fastestmirror
base | 3.6 kB ::
epel/x86_64/metalink | 7.0 kB ::
epel | 3.2 kB ::
extras | 3.4 kB ::
updates | 3.4 kB ::
(/): epel/x86_64/group_gz | kB ::
(/): epel/x86_64/updateinfo | kB ::
(/): extras//x86_64/primary_db | kB ::
(/): epel/x86_64/primary | 3.6 MB ::
(/): updates//x86_64/primary_db | 4.3 MB ::
Loading mirror speeds from cached hostfile
* base: mirrors.shu.edu.cn
* epel: mirrors.tongji.edu.cn
* extras: mirrors..com
* updates: mirrors..com
epel /
Resolving Dependencies
--> Running transaction check
---> Package mysql-utilities.noarch :1.3.-.el7 will be installed
--> Processing Dependency: mysql-connector-python for package: mysql-utilities-1.3.-.el7.noarch
--> Running transaction check
---> Package mysql-connector-python.noarch :1.1.-.el7 will be installed
--> Finished Dependency Resolution ... //Omitted. Installed:
mysql-utilities.noarch :1.3.-.el7 Dependency Installed:
mysql-connector-python.noarch :1.1.-.el7 Complete!
Restore the table structure by mysqlfrm.
[root@zlm2 :: ~]
#cd /data/backup/ [root@zlm2 :: /data/backup]
#ls -l|grep sbtest4
-rw-r----- root root Aug : sbtest4.frm
-rw-r----- root root Aug : sbtest4.ibd [root@zlm2 :: /data/backup]
#mysqlfrm --basedir=/usr/local/mysql --port= --diagnostic ./sbtest4.frm
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: Cannot generate character set or collation names without the --server option.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for ./sbtest4.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement: CREATE TABLE `sbtest4` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL,
`c` char() NOT NULL,
`pad` char() NOT NULL,
PRIMARY KEY `PRIMARY` (`id`),
KEY `k_4` (`k`)
) ENGINE=InnoDB; #...done.
Create a same table structure in the new instance using the restored "create table" statement.
[root@zlm2 :: /data/backup]
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , 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. zlm@192.168.56.101: [(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mrbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) zlm@192.168.56.101: [(none)]>create database sysbench;
Query OK, row affected (0.00 sec) zlm@192.168.56.101: [(none)]>use sysbench
Database changed
zlm@192.168.56.101: [sysbench]>show tables;
Empty set (0.00 sec) zlm@192.168.56.101: [sysbench]>CREATE TABLE `sbtest4` (
-> `id` int() NOT NULL AUTO_INCREMENT,
-> `k` int() NOT NULL,
-> `c` char() NOT NULL,
-> `pad` char() NOT NULL,
-> PRIMARY KEY `PRIMARY` (`id`),
-> KEY `k_4` (`k`)
-> ) ENGINE=InnoDB;
ERROR (): Column length too big for column 'c' (max = ); use BLOB or TEXT instead
zlm@192.168.56.101: [sysbench]>CREATE TABLE `sbtest4` (
-> `id` int() NOT NULL AUTO_INCREMENT,
-> `k` int() NOT NULL,
-> `c` char() NOT NULL,
-> `pad` char() NOT NULL,
-> PRIMARY KEY `PRIMARY` (`id`),
-> KEY `k_4` (`k`)
-> ) ENGINE=InnoDB;
ERROR (42S02): Table 'sysbench.sbtest4' doesn't exist
zlm@192.168.56.101: [sysbench]>CREATE TABLE `sbtest4_bak` (
-> `id` int() NOT NULL AUTO_INCREMENT,
-> `k` int() NOT NULL,
-> `c` char() NOT NULL,
-> `pad` char() NOT NULL,
-> PRIMARY KEY `PRIMARY` (`id`),
-> KEY `k_4` (`k`)
-> ) ENGINE=InnoDB;
Query OK, rows affected (0.01 sec) zlm@192.168.56.101: [sysbench]>rename table sbtest4_bak to sbtest4;
Query OK, rows affected (0.00 sec) zlm@192.168.56.101: [sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest4 |
+--------------------+
row in set (0.00 sec) zlm@192.168.56.101: [sysbench]>show create table sbtest4\G
*************************** . row ***************************
Table: sbtest4
Create Table: CREATE TABLE `sbtest4` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL,
`c` char() NOT NULL,
`pad` char() NOT NULL,
PRIMARY KEY (`id`),
KEY `k_4` (`k`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
row in set (0.00 sec) zlm@192.168.56.101: [sysbench]>select count(*) from sbtest4;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.00 sec)
Discard the tablesapce of new table "sbtest4".
zlm@192.168.56.101: [sysbench]>alter table sbtest4 discard tablespace;
Query OK, rows affected (0.00 sec) [root@zlm2 :: /data/mysql/mysql3306/data/sysbench]
#ls -l
total
-rw-r----- mysql mysql Aug : db.opt
-rw-r----- mysql mysql Aug : sbtest4.frm //After the discard operation,the new ibd file has gone.
Copy the ibd file of table "sbtest4" to the sysbench directory in datadir(notice the owner of file).
[root@zlm2 :: /data/backup]
#cp sbtest4.ibd /data/mysql/mysql3306/data/sysbench/ [root@zlm2 :: /data/backup]
#ll /data/mysql/mysql3306/data/sysbench/ |grep sbtest4
-rw-r----- mysql mysql Aug : sbtest4.frm
-rw-r----- root root Aug : sbtest4.ibd [root@zlm2 :: /data/backup]
#chown mysql.mysql /data/mysql/mysql3306/data/sysbench/sbtest4.ibd [root@zlm2 :: /data/backup]
#ll /data/mysql/mysql3306/data/sysbench/ |grep sbtest4
-rw-r----- mysql mysql Aug : sbtest4.frm
-rw-r----- mysql mysql Aug : sbtest4.ibd
Import the original tablespace of table "sbtest4".
zlm@192.168.56.101: [sysbench]>alter table sbtest4 import tablespace;
Query OK, rows affected, warning (1.77 sec) zlm@192.168.56.101: [sysbench]>select count(*) from sbtest4;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.01 sec) //Now the table has been rescued.
//Because of the destroying of ibdata1 in the original instance,it should be restored by Xtrabackup again.
- This method is only used to resuce a single table without backup when MySQL instance cannot startup beause of the destoryed ibdata file.
- mysqlfrm is a tool which can load table structure from .frm files.We need to install the mysql-utilities package first.
- If we don't have a properly full Xtrabackup and binlog,the .ibd file may lose the undo information on target table.In this situation,it's an incompletely recovery.
ibdata1文件损坏时恢复InnoDB单表测试的更多相关文章
- Innodb单表数据物理恢复
本文将介绍使用物理备份恢复Innodb单表数据的方法 前言: 随着innodb的普及,innobackup也成为了主流备份方式.物理备份对于新建slave,全库恢复的需求都能从容应对. 但当面临单表数 ...
- 记录SQL Server2008日志文件损坏的恢复过程
记录SQL Server2008日志文件损坏的恢复过程: 环境: 系 统:Windows Server2003 数据库:SQL Server2008 故障原因: 通过mstsc链接同一服务器时,用户界 ...
- mysql启动后随即关闭问题解决(ibdata1文件损坏导致)
机房一台服务器上的mysql运行一段时间了,突然出现了一个很奇怪的现象:重启后无法恢复了!准确情况是:启动mysql后随即就又关闭了. 查看mysql错误日志如下: 160920 22:41:41 m ...
- mongodb文件损坏的恢复--无可恢复数据
1.mongodb 启动异常error code 100,检查日志,数据文件损坏 2 检查collection-15-6548623434943640018.wt 可恢复数据,为空,不存在恢复的数据 ...
- django第8天(在测试文件中运行django项目|单表操作)
django第8天 在测试文件中运行django项目 1.将项目配置文件数据库该为mysql,修改配置信息 PORT = '127.0.0.1' DATABASES = { 'default': { ...
- 详解MySQL表空间以及ibdata1文件过大问题
ibdata1文件过大 原因分析 ibdata1是一个用来构建innodb系统表空间的文件,关于系统表空间详细介绍参考MySQL官网文档 上面是一个数据库的ibdata1文件,达到了780多G,而且还 ...
- ibdata1文件--缩小mysql数据库的ibdata1文件
摘要 在MySQL数据库中,如果不指定innodb_file_per_table参数,单独存在每个表的数据,MySQL的数据都会存放在ibdata1文件. mysql ibdata1存放数据,索引等, ...
- Oracle - 各类文件损坏处理办法(附实验步骤)
一.概述 本文将给大家介绍oracle各类文件损坏的现象和应对策略,请注意所有的恢复都是基于有备份的情况,所以请开启数据库的日常备份.文章将从以下文件展开 a. 密码文件 b. 参数文件 c. 控制文 ...
- SQL Server单表已700w+将普通表转换成分区表
最近项目中,某个表数据量爆发时增长,单表已700w+,读写性能急剧下降,所以考虑加入分区表以解燃眉之急,后续还是要分表分库,当然这是后话.下面简要说一下将普通表转为分区表的步骤. 一.创建文件组 ...
随机推荐
- 线段树扫描线总结(POJ 1389)
扫描线算是线段树的一个比较特殊的用法,虽然NOIP不一定会考,但是学学还是有用的,况且也不是很难理解. 以前学过一点,不是很透,今天算是搞懂了. 就以这道题为例吧:嘟嘟嘟 题目的意思是在一个二维坐标系 ...
- 【转】Android总结之drawable(hdpi,mdpi,ldpi)文件夹的使用
做Android有段时间了,但是好多细节还没有深入理解,关于Android中drawable文件夹的使用理解的就不是很深入. Android为开发者提供了两种解决适配问题的方法,第一种方式是使用dip ...
- Go转json数组
Go转json数组 最近因需要要调用gitlab的API,其中有一个是根据私有token获取Repositories列表 由于返回结果是一个json数组,单纯使用json.Unmarshal没法实现, ...
- 关于math.random()的问题
今天在写一个关于随机数的小程序时,在程序执行时,发现随机数不能执行随机,随机结果始终为1. 下面贴上一开始错误的代码 int i = (int)Math.random()*3+1; 无论运行多少次,结 ...
- iOS之点击通知栏跳转应用的相关页面
当远程推送通知到达应用,有3个相关的方法是用来处理这个通知的. - (BOOL)application:(UIApplication *)application didFinishLaunchingW ...
- PTA 最多删除3个字符(DP) - 30分
给定一个全部由小写英文字母组成的字符串,允许你至多删掉其中 3 个字符,结果可能有多少种不同的字符串? 输入格式: 输入在一行中给出全部由小写英文字母组成的.长度在区间 [4, 1] 内的字符串. 输 ...
- windows平台下获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
转自http://blog.csdn.net/jhqin/article/details/5548656,如有侵权,请联系本人删除,谢谢!! 头文件:WMI_DeviceQuery.h /* ---- ...
- MySQL高可用之MGR安装测试(续)
Preface I've implemented the Group Replication with three servers yesterday,What a shame it ...
- solr6.6教程-core的添加(二)
1.什么是core core是solr的一个索引库,可以理解为一个数据库,core可以根据需要,创建多个. 2.创建core 首先进入到solrhome文件夹(D:\solrhome),创建一个文件夹 ...
- Recycler实现瀑布流
(开发环境Android studio) 首先,在开发环境中添加引用(在外层的build.gradle文件下的dependencies里面添加如下引用) implementation 'com.and ...