Innodb的ibdata數據文件誤刪除後的操作流程:
注意:誤刪除後,你的數據庫是還可以工作的,數據照樣可以寫入,切記,千萬不要把mysqld進程殺死,否則就沒法挽救了。
首先找到mysqld的進程pid,如pid是 1111
ll /proc/1111/fd |egrep 'ib_|ibdata'
10 -> /opt/mysql/data/ib_logfile111 -> /opt/mysql/data/ib_logfile2
12 -> /opt/mysql/data/ibdata1
13 -> /opt/mysql/data/ib_logfile0
12就是你要找的文件。
這時可以關掉前端服務,或者執行:flush tables with read lock;是爲了停止繼續寫入,便於後邊的恢復操作。
讓髒頁儘快刷入到磁盤裏。set global innodb_max_diryt_pages_pct=0;時刻查看binlog日誌寫入情況。show master status;也可以進行一些show engine innodb status\G 對一些髒頁的查看。
以上工作都處理好後,就可以進行恢復操作了。cp 12 /opt/mysql/data/ibdata1,然後修改相應的權限。重啓mysql即可。
不要在生產環境下進行測試哦。