误删ibdata1文件恢复方法
2016-02-09 10:52
537 查看
注意:以下演示过程前提为mysqld进程仍在运行中,否则无法使用下面演示过程进行恢复!
1.手工制造故障,删除ibdata1文件,注意不要重启mysql
shell > rm -rf ibdata1
2.登录mysql,进行如下操作
mysql > FLUSH TABLES WITH READ LOCK; #全局加读锁,阻塞Innodb继续写入数据
mysql > SHOW engine innodb STATUS; #查看innodb status中的LSN位置
#找到这2个关键值
Log sequence number 1626744
Last checkpoint at 1626744
1)如果相减为0,则表示写入到磁盘中
#如果不为0,可以加速写入
mysql > SET global innodb_max_dirty_pages_pct=0;
2)同时要保证
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
insert buffer thread. ibuf的大小应该=1
3) purge thread,它應該purge了全部的transactions
------------
TRANSACTIONS
------------
Trx id counter 14085
Purge done for trx's n:o < 0 undo n:o < 0 state: running but idle
4)确保innodb不在进行写操作
SHOW engine innodb STATUS
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
172 OS file reads, 5 OS file writes, 5 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
3. 确认无误之后,/proc/pid/fd中找出ibdata1文件,(这个pid是mysqld的进程号,如下图:)
![](http://images2015.cnblogs.com/blog/763020/201602/763020-20160209105059527-1329535630.png)
#将ibdata1对应的链接文件5拷贝过去改名
shell > cp /proc/6954/fd/5 /data/mysql3306/ibdata1
4. 更改权限
shell > chown -R mysql.mysql /data/mysql3306/ibdata1
5. 重启[已可以正常登陆]
shell > mysqladmin shutdown -S /tmp/mysql3306.sock
shell > /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf start 3306
shell > mysql -uroot -S /tmp/mysql3306.sock
1.手工制造故障,删除ibdata1文件,注意不要重启mysql
shell > rm -rf ibdata1
2.登录mysql,进行如下操作
mysql > FLUSH TABLES WITH READ LOCK; #全局加读锁,阻塞Innodb继续写入数据
mysql > SHOW engine innodb STATUS; #查看innodb status中的LSN位置
#找到这2个关键值
Log sequence number 1626744
Last checkpoint at 1626744
1)如果相减为0,则表示写入到磁盘中
#如果不为0,可以加速写入
mysql > SET global innodb_max_dirty_pages_pct=0;
2)同时要保证
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
insert buffer thread. ibuf的大小应该=1
3) purge thread,它應該purge了全部的transactions
------------
TRANSACTIONS
------------
Trx id counter 14085
Purge done for trx's n:o < 0 undo n:o < 0 state: running but idle
4)确保innodb不在进行写操作
SHOW engine innodb STATUS
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
172 OS file reads, 5 OS file writes, 5 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
3. 确认无误之后,/proc/pid/fd中找出ibdata1文件,(这个pid是mysqld的进程号,如下图:)
![](http://images2015.cnblogs.com/blog/763020/201602/763020-20160209105059527-1329535630.png)
#将ibdata1对应的链接文件5拷贝过去改名
shell > cp /proc/6954/fd/5 /data/mysql3306/ibdata1
4. 更改权限
shell > chown -R mysql.mysql /data/mysql3306/ibdata1
5. 重启[已可以正常登陆]
shell > mysqladmin shutdown -S /tmp/mysql3306.sock
shell > /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf start 3306
shell > mysql -uroot -S /tmp/mysql3306.sock
相关文章推荐
- uva 11401 荣斥
- 1007. Maximum Subsequence Sum (25)
- Android Annotations环境搭建(Android Studio)
- 【Nginx笔记】nginx配置文件具体解释
- SHUOJ 1553 滑雪问题(大数据)(BFS)
- ZOJ1061
- xsl-fo图文混排的问题解决
- Aireplay-ng的6种攻击模式详解
- POJ3624(01背包:滚动 实现)
- android调用音乐播放器,三种方
- uva 11538 组合
- 志不强者智不达
- 深入理解Aireplay-ng各种攻击及其原理
- AJAX
- 智慧北京开发第三天(上)
- Matches正则使用提取内容
- Jquery库和自己定义库的区别
- C++自制Redis数据库(八)基本数据结构--String
- eclipse安装和使用
- auto-boxing, uboxing,以及缓存问题