人工误删innodb数据文件ibdata后如何恢复

第一阶段:模拟破坏试验:

二:进行数据文件的恢复:

1.找到mysqld服务的进程号

ps -ef | egrep mysqld

2.根据进程号找到删除掉的相关的数据文件

ll /proc/pid/fd

3.锁定数据库,禁止其他的写操作

flush tables with read lock;

4.分步骤验证当前数据库确实已经没有了写操作

  (1)首先将内存中的脏页刷新到磁盘中

  set global innodb_max_dirty_pages_pct=0;

  (2)查看binlog日志文件写入情况,确保file和post不会发生变化

  show master status;

  (3) 通过查看innodb状态信息,将状态信息可以先保存到一个文件中:

  mysql -uroot -p -e 'show engine innodb statusG' > 111.txt

  (4) 确定后台purge进程把undo log全部清除掉,事物ID要一致

  [mysql@localhost ~]$ cat 222.txt | egrep undo
  Purge done for trx's n:o < BA22 undo n:o < 0

  (5)确定log日志的序列号不会变化

  [mysql@localhost ~]$ cat 222.txt | egrep 'Log|Last'
  Log sequence number 1221967116
  Log flushed up to 1221967116
  Last checkpoint at 1221967116

  (6)确保脏页数量为0

  [mysql@localhost ~]$ cat 222.txt | egrep 'db pages'
  Modified db pages 0

  (7)确保插入、更新、删除为0

  [mysql@localhost ~]$ cat 222.txt | egrep 'inserts/s'
  0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s

5.将误删除的数据文件从/proc/pid/fd文件夹中拷贝到数据目中

6.更改数据文件的权限

7.重启mysqld服务

你将来想成为什么样子,就一定会成为什么样子,只要你努力坚持的去做!!!
原文地址:https://www.cnblogs.com/kucha/p/4874432.html