MySQL 5.6.26 誤刪ibdata恢復
[root@hank-yoon ~]# ps -ef | grep mysql
root 1129 1 0 15:30 pts/0 00:00:00 /bin/sh /export/servers/mysql/bin/mysqld_safe --datadir=/export/data/mysql/data/ --pid-file=/export/data/mysql/mysql.pid
mysql 2284 1129 2 15:30 pts/0 00:00:01 /export/servers/mysql/bin/mysqld --basedir=/export/servers/mysql --datadir=/export/data/mysql/data/ --plugin-dir=/export/servers/mysql/lib/plugin --user=mysql --log-error=/export/data/mysql/log/error.log --open-files-limit=65535 --pid-file=/export/data/mysql/mysql.pid --socket=/export/data/mysql/tmp/mysql.sock --port=3306
root 2343 1101 0 15:31 pts/0 00:00:00 grep mysql
[root@hank-yoon ~]# service mysql status
SUCCESS! MySQL running (2284)
[root@hank-yoon ~]# cd /export/data/mysql/data/
[root@hank-yoon data]# ls
a.sql binlog-rollback.pl c.sql ibdata1 ib_logfile0 ib_logfile2 mysql mysql-bin.000035 mysql-bin%Y%M%d.000001 performance_schema sakila yoon
auto.cnf b.sql hank ibdata2 ib_logfile1 modify.pl mysql-bin.000034 mysql-bin.index mysql-bin%Y%M%d.index rollback.pl test
[root@hank-yoon data]# rm -rf ibdata1 ibdata2
注意:無備份,誤刪ibdata檔案,資料庫千萬不要重啟,否則神仙下凡都沒用了!
[root@hank-yoon data]# ps -ef | grep mysql
root 1129 1 0 15:30 pts/0 00:00:00 /bin/sh /export/servers/mysql/bin/mysqld_safe --datadir=/export/data/mysql/data/ --pid-file=/export/data/mysql/mysql.pid
mysql 2284 1129 1 15:30 pts/0 00:00:01 /export/servers/mysql/bin/mysqld --basedir=/export/servers/mysql --datadir=/export/data/mysql/data/ --plugin-dir=/export/servers/mysql/lib/plugin --user=mysql --log-error=/export/data/mysql/log/error.log --open-files-limit=65535 --pid-file=/export/data/mysql/mysql.pid --socket=/export/data/mysql/tmp/mysql.sock --port=3306
root 2362 1101 0 15:32 pts/0 00:00:00 grep mysql
[root@hank-yoon data]# ll /proc/2284/fd | egrep 'ib_|ibdata'
lrwx------. 1 root root 64 Jul 12 15:35 10 -> /export/data/mysql/data/ib_logfile0
lrwx------. 1 root root 64 Jul 12 15:35 11 -> /export/data/mysql/data/ib_logfile1
lrwx------. 1 root root 64 Jul 12 15:35 12 -> /export/data/mysql/data/ib_logfile2
lrwx------. 1 root root 64 Jul 12 15:35 4 -> /export/data/mysql/data/ibdata1 (deleted)
lrwx------. 1 root root 64 Jul 12 15:35 9 -> /export/data/mysql/data/ibdata2 (deleted)
鎖表,禁止再寫入資料,以便恢復工作
[root@hank-yoon data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
root((none))> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)
root((none))>
不能停業務,鎖表後刷髒頁
root((none))> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)
root((none))> set global innodb_max_dirty_pages_pct=0;
Query OK, 0 rows affected (0.00 sec)
透過show mater status確定file和position不再變化
root((none))> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000035 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
透過root((none))> show engine innodb status\G檢視是否還有寫入
TRANSACTIONS
------------
Trx id counter 59143
Purge done for trx's n:o < 58676 undo n:o < 0 state: running but idle
##確保後臺Purge程式把undo log全部清除掉,事務ID要一致
History list length 462
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 1, OS thread handle 0x7f5cec6eb700, query id 9 localhost root init
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
# insert buffer合併插入快取等於1
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 2365241, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 14149940429
Log flushed up to 14149940429
Pages flushed up to 14149940429
Last checkpoint at 14149940429
#三個值相同
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1098907648; in additional pool allocated 0
Dictionary memory allocated 59957
Buffer pool size 65528
Free buffers 65118
Database pages 410
Old database pages 0
Modified db pages 0
#確保髒資料為0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 410, created 0, written 5
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 410, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Main thread process no. 2284, id 140037101377280, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
#確保插入,更新,刪除為0
再次找到這幾個檔案,恢復
[root@hank-yoon data]# ll /proc/2284/fd | egrep 'ib_|ibdata'
lrwx------. 1 root root 64 Jul 12 15:35 10 -> /export/data/mysql/data/ib_logfile0
lrwx------. 1 root root 64 Jul 12 15:35 11 -> /export/data/mysql/data/ib_logfile1
lrwx------. 1 root root 64 Jul 12 15:35 12 -> /export/data/mysql/data/ib_logfile2
lrwx------. 1 root root 64 Jul 12 15:35 4 -> /export/data/mysql/data/ibdata1 (deleted)
lrwx------. 1 root root 64 Jul 12 15:35 9 -> /export/data/mysql/data/ibdata2 (deleted)
[root@hank-yoon data]# cp /proc/2284/fd/4 /export/data/mysql/data/ibdata1
[root@hank-yoon data]# cp /proc/2284/fd/9 /export/data/mysql/data/ibdata2
修改許可權
[root@hank-yoon data]# cd /export/data/mysql/data/
[root@hank-yoon data]# ls -ltr
total 4980844
drwx------. 2 mysql mysql 4096 Sep 30 2015 performance_schema
drwx------. 2 mysql mysql 4096 Sep 30 2015 mysql
-rw-rw----. 1 mysql mysql 56 Sep 30 2015 auto.cnf
drwx------. 2 mysql mysql 4096 Nov 18 2015 test
-rw-r--r--. 1 root root 15886 Dec 24 2015 binlog-rollback.pl
-rwxr-xr-x. 1 root root 2766 Jan 4 2016 modify.pl
-rw-r--r--. 1 root root 2766 Jan 5 2016 rollback.pl
drwx------. 2 mysql mysql 4096 Mar 22 21:54 hank
-rw-rw----. 1 mysql mysql 25 Apr 13 10:04 mysql-bin%Y%M%d.index
-rw-rw----. 1 mysql mysql 143 Apr 13 10:05 mysql-bin%Y%M%d.000001
-rw-rw----. 1 mysql mysql 268435456 Jun 21 10:07 ib_logfile1
drwx------. 2 mysql mysql 4096 Jun 21 15:02 sakila
drwx------. 2 mysql mysql 4096 Jun 29 14:50 yoon
-rw-r--r--. 1 root root 5087 Jun 29 14:53 a.sql
-rw-r--r--. 1 root root 124 Jun 29 14:55 b.sql
-rw-r--r--. 1 root root 47 Jun 29 14:56 c.sql
-rw-rw----. 1 mysql mysql 2027 Jul 12 15:30 mysql-bin.000034
-rw-rw----. 1 mysql mysql 120 Jul 12 15:30 mysql-bin.000035
-rw-rw----. 1 mysql mysql 38 Jul 12 15:30 mysql-bin.index
-rw-rw----. 1 mysql mysql 268435456 Jul 12 15:30 ib_logfile2
-rw-rw----. 1 mysql mysql 268435456 Jul 12 15:30 ib_logfile0
-rw-r-----. 1 root root 2147483648 Jul 12 15:55 ibdata1
-rw-r-----. 1 root root 2147483648 Jul 12 15:55 ibdata2
[root@hank-yoon data]# chown -R mysql.mysql ibdata1 ibdata2
重啟登入資料庫
[root@hank-yoon data]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL... SUCCESS!
[root@hank-yoon data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
root((none))>
root 1129 1 0 15:30 pts/0 00:00:00 /bin/sh /export/servers/mysql/bin/mysqld_safe --datadir=/export/data/mysql/data/ --pid-file=/export/data/mysql/mysql.pid
mysql 2284 1129 2 15:30 pts/0 00:00:01 /export/servers/mysql/bin/mysqld --basedir=/export/servers/mysql --datadir=/export/data/mysql/data/ --plugin-dir=/export/servers/mysql/lib/plugin --user=mysql --log-error=/export/data/mysql/log/error.log --open-files-limit=65535 --pid-file=/export/data/mysql/mysql.pid --socket=/export/data/mysql/tmp/mysql.sock --port=3306
root 2343 1101 0 15:31 pts/0 00:00:00 grep mysql
[root@hank-yoon ~]# service mysql status
SUCCESS! MySQL running (2284)
[root@hank-yoon ~]# cd /export/data/mysql/data/
[root@hank-yoon data]# ls
a.sql binlog-rollback.pl c.sql ibdata1 ib_logfile0 ib_logfile2 mysql mysql-bin.000035 mysql-bin%Y%M%d.000001 performance_schema sakila yoon
auto.cnf b.sql hank ibdata2 ib_logfile1 modify.pl mysql-bin.000034 mysql-bin.index mysql-bin%Y%M%d.index rollback.pl test
[root@hank-yoon data]# rm -rf ibdata1 ibdata2
注意:無備份,誤刪ibdata檔案,資料庫千萬不要重啟,否則神仙下凡都沒用了!
[root@hank-yoon data]# ps -ef | grep mysql
root 1129 1 0 15:30 pts/0 00:00:00 /bin/sh /export/servers/mysql/bin/mysqld_safe --datadir=/export/data/mysql/data/ --pid-file=/export/data/mysql/mysql.pid
mysql 2284 1129 1 15:30 pts/0 00:00:01 /export/servers/mysql/bin/mysqld --basedir=/export/servers/mysql --datadir=/export/data/mysql/data/ --plugin-dir=/export/servers/mysql/lib/plugin --user=mysql --log-error=/export/data/mysql/log/error.log --open-files-limit=65535 --pid-file=/export/data/mysql/mysql.pid --socket=/export/data/mysql/tmp/mysql.sock --port=3306
root 2362 1101 0 15:32 pts/0 00:00:00 grep mysql
[root@hank-yoon data]# ll /proc/2284/fd | egrep 'ib_|ibdata'
lrwx------. 1 root root 64 Jul 12 15:35 10 -> /export/data/mysql/data/ib_logfile0
lrwx------. 1 root root 64 Jul 12 15:35 11 -> /export/data/mysql/data/ib_logfile1
lrwx------. 1 root root 64 Jul 12 15:35 12 -> /export/data/mysql/data/ib_logfile2
lrwx------. 1 root root 64 Jul 12 15:35 4 -> /export/data/mysql/data/ibdata1 (deleted)
lrwx------. 1 root root 64 Jul 12 15:35 9 -> /export/data/mysql/data/ibdata2 (deleted)
鎖表,禁止再寫入資料,以便恢復工作
[root@hank-yoon data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
root((none))> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)
root((none))>
不能停業務,鎖表後刷髒頁
root((none))> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)
root((none))> set global innodb_max_dirty_pages_pct=0;
Query OK, 0 rows affected (0.00 sec)
透過show mater status確定file和position不再變化
root((none))> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000035 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
透過root((none))> show engine innodb status\G檢視是否還有寫入
TRANSACTIONS
------------
Trx id counter 59143
Purge done for trx's n:o < 58676 undo n:o < 0 state: running but idle
##確保後臺Purge程式把undo log全部清除掉,事務ID要一致
History list length 462
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 1, OS thread handle 0x7f5cec6eb700, query id 9 localhost root init
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
# insert buffer合併插入快取等於1
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 2365241, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 14149940429
Log flushed up to 14149940429
Pages flushed up to 14149940429
Last checkpoint at 14149940429
#三個值相同
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1098907648; in additional pool allocated 0
Dictionary memory allocated 59957
Buffer pool size 65528
Free buffers 65118
Database pages 410
Old database pages 0
Modified db pages 0
#確保髒資料為0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 410, created 0, written 5
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 410, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Main thread process no. 2284, id 140037101377280, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
#確保插入,更新,刪除為0
再次找到這幾個檔案,恢復
[root@hank-yoon data]# ll /proc/2284/fd | egrep 'ib_|ibdata'
lrwx------. 1 root root 64 Jul 12 15:35 10 -> /export/data/mysql/data/ib_logfile0
lrwx------. 1 root root 64 Jul 12 15:35 11 -> /export/data/mysql/data/ib_logfile1
lrwx------. 1 root root 64 Jul 12 15:35 12 -> /export/data/mysql/data/ib_logfile2
lrwx------. 1 root root 64 Jul 12 15:35 4 -> /export/data/mysql/data/ibdata1 (deleted)
lrwx------. 1 root root 64 Jul 12 15:35 9 -> /export/data/mysql/data/ibdata2 (deleted)
[root@hank-yoon data]# cp /proc/2284/fd/4 /export/data/mysql/data/ibdata1
[root@hank-yoon data]# cp /proc/2284/fd/9 /export/data/mysql/data/ibdata2
修改許可權
[root@hank-yoon data]# cd /export/data/mysql/data/
[root@hank-yoon data]# ls -ltr
total 4980844
drwx------. 2 mysql mysql 4096 Sep 30 2015 performance_schema
drwx------. 2 mysql mysql 4096 Sep 30 2015 mysql
-rw-rw----. 1 mysql mysql 56 Sep 30 2015 auto.cnf
drwx------. 2 mysql mysql 4096 Nov 18 2015 test
-rw-r--r--. 1 root root 15886 Dec 24 2015 binlog-rollback.pl
-rwxr-xr-x. 1 root root 2766 Jan 4 2016 modify.pl
-rw-r--r--. 1 root root 2766 Jan 5 2016 rollback.pl
drwx------. 2 mysql mysql 4096 Mar 22 21:54 hank
-rw-rw----. 1 mysql mysql 25 Apr 13 10:04 mysql-bin%Y%M%d.index
-rw-rw----. 1 mysql mysql 143 Apr 13 10:05 mysql-bin%Y%M%d.000001
-rw-rw----. 1 mysql mysql 268435456 Jun 21 10:07 ib_logfile1
drwx------. 2 mysql mysql 4096 Jun 21 15:02 sakila
drwx------. 2 mysql mysql 4096 Jun 29 14:50 yoon
-rw-r--r--. 1 root root 5087 Jun 29 14:53 a.sql
-rw-r--r--. 1 root root 124 Jun 29 14:55 b.sql
-rw-r--r--. 1 root root 47 Jun 29 14:56 c.sql
-rw-rw----. 1 mysql mysql 2027 Jul 12 15:30 mysql-bin.000034
-rw-rw----. 1 mysql mysql 120 Jul 12 15:30 mysql-bin.000035
-rw-rw----. 1 mysql mysql 38 Jul 12 15:30 mysql-bin.index
-rw-rw----. 1 mysql mysql 268435456 Jul 12 15:30 ib_logfile2
-rw-rw----. 1 mysql mysql 268435456 Jul 12 15:30 ib_logfile0
-rw-r-----. 1 root root 2147483648 Jul 12 15:55 ibdata1
-rw-r-----. 1 root root 2147483648 Jul 12 15:55 ibdata2
[root@hank-yoon data]# chown -R mysql.mysql ibdata1 ibdata2
重啟登入資料庫
[root@hank-yoon data]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL... SUCCESS!
[root@hank-yoon data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
root((none))>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-2121914/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL資料災難挽救之ibdata檔案誤刪恢復MySql
- 【Mysql】誤刪ibdata ib_logfile等檔案的恢復MySql
- mysql誤刪資料恢復MySql資料恢復
- Mysql 誤刪資料進行恢復MySql
- 14、MySQL Case-線上表誤刪除恢復MySql
- MySQL資料庫表誤刪除恢復(一)MySql資料庫
- MySQL誤刪物理檔案的恢復(Linux)MySqlLinux
- mysql ibdata1 ib_logfile的恢復MySql
- MySQL 5.6.26 通過frm & ibd 恢復資料過程MySql
- MySQL 5.6.26 透過frm & ibd 恢復資料過程MySql
- mysql 5.7 刪除ibdata1 、ib_logfile 檔案的資料恢復MySql資料恢復
- MySQL誤刪root使用者恢復一例MySql
- Oracle恢復誤刪資料Oracle
- Mysql update誤操作恢復MySql
- 電腦照片誤刪了怎麼恢復?電腦誤刪檔案照片恢復教程
- eclipse 恢復誤刪檔案Eclipse
- Mac誤刪照片怎麼恢復Mac
- lsof恢復誤刪的檔案
- oracle恢復誤刪除資料Oracle
- Oracle閃回刪除恢復誤刪資料Oracle
- 【MySQL】恢復誤操作的方法MySql
- 電腦檔案誤刪除了怎麼恢復找回?誤刪電腦資料恢復方法教程資料恢復
- Oracle恢復誤操作刪除掉的表Oracle
- Linux恢復誤刪的資料Linux
- lsof恢復oracle誤刪除檔案Oracle
- 磁碟誤刪卷資料恢復工具資料恢復
- 詳解:如何恢復MySQL資料庫下誤刪的資料MySql資料庫
- 未刪除的表結構從ibdata1檔案進行恢復
- Mongodb資料庫誤刪後的恢復MongoDB資料庫
- 如何有效恢復誤刪的HDFS檔案
- 電腦誤刪檔案怎麼恢復?
- 被誤刪的檔案快速恢復方法
- 【Linux】ext3grep 誤刪恢復Linux
- Oracle-誤刪資料恢復(短期內)Oracle資料恢復
- DB2 恢復誤刪除的表DB2
- 使用lsof恢復誤刪除的檔案
- 閃回查詢恢復誤刪資料
- 儲存過程誤刪除的恢復儲存過程