在關閉時,參數innodb_fast_shutdown影響着表的存儲引擎爲InnoDB的行爲。
該參數取值爲0、1、2
0 代表黨MySql關閉時,InnoDB需要完成所有的full purge 和 merge insert buffer操作,這會需要一些時間。1 代表不需要完成上述的full purge ,merge insert buffer操作,但是在緩衝池的一些數據髒頁還是會刷新到磁盤。2 代表不完成full purge ,merge insert buffer操作,也 不將緩衝池中的數據髒頁寫回磁盤,而是將日誌都寫入日誌文件。這樣不會有任何事物會丟失,但是Mysql數據庫下次啓動時,會執行recovery
參數Innodb_force_recovery影響了整個InnoDB存儲引擎的恢復狀況。默認0
測試:
環境:innodb_fast_shutdown = 2
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
innodb_force_recovery影響整個InnoDB存儲引擎的恢復狀況。默認爲0,表示當需要恢復時執行所有的
恢復操作。當不能進行有效的恢復操作時,mysql有可能無法啓動,並記錄下錯誤日誌。
innodb_force_recovery可以設置爲1-6,大的數字包含前面所有數字的影響。
當設置參數值大於0後,可以對錶進行select,create,drop操作,但insert,update或者delete這類操作
是不允許的。
1(SRV_FORCE_IGNORE_CORRUPT):忽略檢查到的corrupt頁。
2(SRV_FORCE_NO_BACKGROUND):阻止主線程的運行,如主線程需要執行full purge操作,會導致crash。
3(SRV_FORCE_NO_TRX_UNDO):不執行事務回滾操作。
4(SRV_FORCE_NO_IBUF_MERGE):不執行插入緩衝的合併操作。
5(SRV_FORCE_NO_UNDO_LOG_SCAN):不查看重做日誌,InnoDB存儲引擎會將未提交的事務視爲已提交。
6(SRV_FORCE_NO_LOG_REDO):不執行前滾的操作。
測試一
破壞xbb5.ibd表
刪除了數據頁
innodb_force_recovery = 1-3 表不可用
報ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock' 錯誤
innodb_force_recovery = 4-6 select * 可用,select count(*) 不準缺
報ERROR 2013 (HY000): Lost connection to MySQL server during query錯誤
測試二
創建事務,不提交
root@test 04:32:32>begin;
Query OK, 0 rows affected (0.01 sec)
root@test 04:33:14>update test set b = b+100;
Query OK, 9999 rows affected (0.18 sec)
Rows matched: 9999 Changed: 9999 Warnings: 0
innodb_force_recovery =0 要檢查回滾操作
130626 16:32:20 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 12544
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:32:21 InnoDB: Rolling back trx with id 0 12032, 9999 rows to undo
InnoDB: Progress in percents: 1130626 16:32:21 InnoDB: Started; log sequence number 0 4330016
130626 16:32:21 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:32:21 [Note] Starting crash recovery...
130626 16:32:21 [Note] Crash recovery finished.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97130626 16:32:21 [Note] Event Scheduler: Loaded 0 events
130626 16:32:21 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
98 99 100
InnoDB: Rolling back of trx id 0 12032 completed
130626 16:32:21 InnoDB: Rollback of non-prepared transactions completed
如果回滾數據多,恢復就相對的慢
innodb_force_recovery =2 阻止主線程的運行,如主線程需要執行full purge操作,會導致crash。
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 15616
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 17:05:53 InnoDB: Rolling back trx with id 0 15104, 9999 rows to undo
InnoDB: Progress in percents: 1130626 17:05:53 InnoDB: Started; log sequence number 0 13016158
InnoDB: !!! innodb_force_recovery is set to 2 !!!
130626 17:05:53 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 17:05:53 [Note] Starting crash recovery...
130626 17:05:53 [Note] Crash recovery finished.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85130626 17:05:53 [Note] Event Scheduler: Loaded 0 events
130626 17:05:53 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 15104 completed
130626 17:05:53 InnoDB: Rollback of non-prepared transactions completed
innodb_force_recovery =3 不執行回滾操作
130626 16:33:53 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 13056
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
130626 16:33:53 InnoDB: Started; log sequence number 0 6497918
InnoDB: !!! innodb_force_recovery is set to 3 !!!
130626 16:33:53 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:33:53 [Note] Starting crash recovery...
130626 16:33:53 [Note] Crash recovery finished.
130626 16:33:53 [Note] Event Scheduler: Loaded 0 events
130626 16:33:53 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
innodb_force_recovery =5 不查看重做日誌,innodb存儲引擎會將未提交的事務事務已經提交
此時數據已經被update
+----+------+------+------+
| a | b | c | d |
+----+------+------+------+
| 1 | 101 | 1 | 1 |
| 2 | 102 | 2 | 2 |
| 3 | 103 | 3 | 3 |
| 4 | 104 | 4 | 4 |
| 5 | 105 | 5 | 5 |
| 6 | 106 | 6 | 6 |
| 7 | 107 | 7 | 7 |
| 8 | 108 | 8 | 8 |
| 9 | 109 | 9 | 9 |
| 10 | 110 | 10 | 10 |
+----+------+------+------+
innodb_force_recovery =6 不執行前滾操作,但是恢復的時候有回滾操作
+----+------+------+------+
| a | b | c | d |
+----+------+------+------+
| 1 | 101 | 1 | 1 |
| 2 | 102 | 2 | 2 |
| 3 | 103 | 3 | 3 |
| 4 | 104 | 4 | 4 |
| 5 | 105 | 5 | 5 |
| 6 | 106 | 6 | 6 |
| 7 | 107 | 7 | 7 |
| 8 | 108 | 8 | 8 |
| 9 | 109 | 9 | 9 |
| 10 | 110 | 10 | 10 |
+----+------+------+------+
130626 16:44:29 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 14080
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:44:29 InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo
InnoDB: Progress in percents: 1130626 16:44:29 InnoDB: Started; log sequence number 0 8680656
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79130626 16:44:29 [Note] Event Scheduler: Loaded 0 events
130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 13057 completed
130626 16:44:29 InnoDB: Rollback of non-prepared transactions completed
130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
130626 16:45:08 [Note] Plugin 'FEDERATED' is disabled.
130626 16:45:08 InnoDB: Initializing buffer pool, size = 2.0G
130626 16:45:08 InnoDB: Completed initialization of buffer pool
InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
InnoDB: Skipping log redo
130626 16:45:08 InnoDB: Started; log sequence number 0 0
InnoDB: !!! innodb_force_recovery is set to 6 !!!
130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:45:08 [Note] Starting crash recovery...
130626 16:45:08 [Note] Crash recovery finished.
130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
130626 16:45:14 InnoDB: error: space object of table test/test,
InnoDB: space id 3 did not exist in memory. Retrying an open.
-+------+------+------+
| 1 | 101 | 1 | 1 |
| 2 | 102 | 2 | 2 |
| 3 | 103 | 3 | 3 |
| 4 | 104 | 4 | 4 |
| 5 | 105 | 5 | 5 |
| 6 | 106 | 6 | 6 |
| 7 | 107 | 7 | 7 |
| 8 | 108 | 8 | 8 |
| 9 | 109 | 9 | 9 |
| 10 | 110 | 10 | 10 |
+----+------+------+------+
130626 16:44:29 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 14080
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:44:29 InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo
InnoDB: Progress in percents: 1130626 16:44:29 InnoDB: Started; log sequence number 0 8680656
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79130626 16:44:29 [Note] Event Scheduler: Loaded 0 events
130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 13057 completed
130626 16:44:29 InnoDB: Rollback of non-prepared transactions completed
130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
130626 16:45:08 [Note] Plugin 'FEDERATED' is disabled.
130626 16:45:08 InnoDB: Initializing buffer pool, size = 2.0G
130626 16:45:08 InnoDB: Completed initialization of buffer pool
InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
InnoDB: Skipping log redo
130626 16:45:08 InnoDB: Started; log sequence number 0 0
InnoDB: !!! innodb_force_recovery is set to 6 !!!
130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:45:08 [Note] Starting crash recovery...
130626 16:45:08 [Note] Crash recovery finished.
130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.1.57-log' socket: '/tmp/mysqld.sock' port: 3306 MySQL Community Server (GPL)
130626 16:45:14 InnoDB: error: space object of table test/test,
InnoDB: space id 3 did not exist in memory. Retrying an open.
mysql 宕機 innodb_force_recovery,innodb_fast_shutdown對數據的影響
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
項目進度管理及成本管理知識要點
hua0221
2019-02-23 13:38:22
防火牆的相關知識介紹及命令
譕淚寳唄
2019-02-23 13:28:55
6:多源複製的實現
shixiazhoujun
2019-02-24 13:04:18
7:基於語句和行復制的優缺點
shixiazhoujun
2019-02-24 13:04:18
詳解MySQL執行原理、邏輯分層、更改數據庫處理引擎
laozhang
2019-02-24 12:43:05
MySQL中InnoDB和MyISAM的差別
jackieban
2019-02-23 13:57:24
SQL mapper文件的審計
橡皮高
2019-02-23 13:51:10
數據庫管理工具 Navicat使用教程:SQL Server中的磁盤加密
Aote222
2019-02-23 13:34:13
Redhat環境MySQL+Apache+PHP環境配置
znlingdong
2019-02-23 13:29:59
MySQL字符集選擇
兩袖春風
2019-02-23 13:28:22
MySQL數據類型之Pk10平臺架設字符串(string)
wojiuyong
2019-02-23 13:25:22
24小時熱門文章