1.用sysbench模拟数据写入
sysbench –test=oltp –mysql-table-engine=innodb –oltp-table-size=1000000 –max-requests=10000 \
–num-threads=100 –mysql-host=127.0.0.1 –mysql-port=3306 –mysql-user=admin –mysql-password=Dmjxjbgc6u \
–mysql-db=test –max-time=600 –mysql-socket=/tmp/mysql3306.sock prepare
2.用rm -f ib*删除数据文件和重做日志文件
数据库可以正常工作,不要把mysqld进程杀死,且不能关闭mysql服务

恢复工作:
a 查到mysqld的pid
[mysql@mvxl0782 binlog]$ netstat -nltp|grep mysqld
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp        0      0 :::3306                     :::*                        LISTEN      18401/mysqld

这里18401
2.利用进程pid查看对应的文件描述符
[mysql@mvxl0782 binlog]$ ll /proc/18401/fd|egrep ‘ib_|ibdata’
lrwx—— 1 mysql mysql 64 8月  11 10:33 10 -> /mysql/server/data/ib_logfile1
lrwx—— 1 mysql mysql 64 8月  11 10:33 11 -> /mysql/server/data/ib_logfile2
lrwx—— 1 mysql mysql 64 8月  11 10:33 4 -> /mysql/server/data/ibdata1
lrwx—— 1 mysql mysql 64 8月  11 10:33 9 -> /mysql/server/data/ib_logfile0

上面的10、11、4和9就是我们要恢复的文件

3、关闭前端业务或执行flush tables with read lock;  不让有数据写入

4、验证有没有数据写入

a.先输入下面命令,让脏页尽快写入到磁盘里
set global innodb_max_dirty_pages_ptc=0;
b.查看binlog日志写入情况,确保file和position没有变化  show master status;
c.最后查看innodb状态信息,确保脏页已刷入到磁盘中
show engine inndodb status\G

TRANSACTIONS
………..
trx id counter A21837
Purge don for trx’s n:o<A21837 undo n:o<0
##确保后台purge进程把undo log全部清除掉,事务ID要一致

INSERT BUFFER AND ADAPTIVE HASH INDEX
Ibuf:size 1,free kust keb 65,seg size67,0 merges
##插入buffer合并插入缓存等于1

LOG
Log sequence number xxxx
Log flushed up to xxxx
Last checkpoint at xxx
##确保这3个值不在变化

BUFFER POOL AND MEMORY
…………
Modified db pages 0
##确保脏页数量为0

ROW OPERATIONS
………………
0.00 inserts/s,0.00 updates/s,0.00 deletes/s,0.00 reads/s
#确保插入、更新、删除为0

5.恢复操作

[mysql@mvxl0782 binlog]$ ll /proc/18401/fd|egrep ‘ib_|ibdata’
lrwx—— 1 mysql mysql 64 8月  11 10:33 10 -> /mysql/server/data/ib_logfile1
lrwx—— 1 mysql mysql 64 8月  11 10:33 11 -> /mysql/server/data/ib_logfile2
lrwx—— 1 mysql mysql 64 8月  11 10:33 4 -> /mysql/server/data/ibdata1
lrwx—— 1 mysql mysql 64 8月  11 10:33 9 -> /mysql/server/data/ib_logfile0

将上面文件复制并改名:

cp 10 /mysql/server/data/ib_logfile1
cp 11 /mysql/server/data/ib_logfile2
cp 4 /mysql/server/data/ibdata1
cp 9 /mysql/server/data/ib_logfile0

授权:
cd /mysql/server/data
chown -R mysql:dba ib*

最后重启mysql

--END--