您好,登錄后才能下訂單哦!
這篇文章主要講解了“Innodb關鍵特性之怎么實現啟動、關閉和恢復”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Innodb關鍵特性之怎么實現啟動、關閉和恢復”吧!
參數innodb_fast_shutdown影響著表的存儲引擎為Innodb的行為,該參數可以取值為0、1、2,默認值為1,支持全動態局設置。
設置為1:關閉MySQL的時候不會做清除臟頁和插入緩沖區的合并操作,也不會將臟頁刷新到磁盤。
設置為0:會做清除臟頁和插入緩沖區的合并操作,也會將臟頁全部刷新到磁盤上面去,但是這個時候關閉的速度也是最慢的。
設置為2:不會做清除臟頁和插入緩沖區的合并操作,也不會將臟頁刷新到磁盤,但是會刷新到redo log里面,再下次啟動
mysql時候恢復。
參數innodb_force_recovery影響了整個Innodb存儲引擎的恢復狀況。該值默認為0,表示當需要恢復時執行所有的恢復操作。當不能進行有效恢復時,如數據頁發生了corruption,Mysql數據庫可能會宕機,并把錯誤寫入錯誤日志中。
但在某些情況下,可能不需要執行完整的恢復操作。例如在進行alter table操作時,這時發生意外,數據庫重啟時會對Innodb表執行回滾操作。對于一個大表,這需要很長時間,甚至可能是幾個小時。這時可以自行恢復,例如將表刪除,從備份中重新將數據導入表中,這些操作可能要快于回滾操作。
innodb_force_recovery可以設置6個非零值:
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):不執行前滾的操作。
備注:當設置innodb_force_recovery大于0后,可以對表進行select、create、drop操作,但insert、update或者delete這類操作是不允許的。
下面做一個實驗,來模擬故障的發生。
查看相關參數:
mysql> show variables like 'innodb_force%'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | innodb_force_load_corrupted | OFF | | innodb_force_recovery | 0 | +-----------------------------+-------+ 2 rows in set (0.01 sec) mysql> show variables like 'innodb_fast%'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | innodb_fast_shutdown | 1 | +----------------------+-------+ 1 row in set (0.01 sec)
手動開啟事務,防止auto commit,并更新1000000條記錄,不提交。
mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> update rank_item set city=5000 limit 1000000; Query OK, 1000000 rows affected (4 min 34.50 sec) Rows matched: 1000000 Changed: 1000000 Warnings: 0
然后kill掉mysql進程,啟動mysql,查看錯誤日志輸出。
2020-08-05T07:07:20.271772Z 0 [Note] InnoDB: Starting in background the rollback of uncommitted transactions 2020-08-05T07:07:20.271806Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2020-08-05T07:07:20.271826Z 0 [Note] InnoDB: Rolling back trx with id 393530, 901725 rows to undo 2020-08-05T07:07:20.271841Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables InnoDB: Progress in percents: 12020-08-05T07:07:20.272012Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2020-08-05T07:07:20.344665Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2020-08-05T07:07:20.346201Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2020-08-05T07:07:20.346228Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2020-08-05T07:07:20.346492Z 0 [Note] InnoDB: Waiting for purge to start 2020-08-05T07:07:20.396629Z 0 [Note] InnoDB: 5.7.26 started; log sequence number 248770956866 2020-08-05T07:07:20.396654Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 30517ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) 2020-08-05T07:07:20.397332Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/data/ib_buffer_pool 2020-08-05T07:07:20.398205Z 0 [Note] Plugin 'FEDERATED' is disabled. 2020-08-05T07:07:20.405796Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2020-08-05T07:07:20.405835Z 0 [Note] Server hostname (bind-address): '*'; port: 16008 2020-08-05T07:07:20.405919Z 0 [Note] IPv6 is available. 2020-08-05T07:07:20.405943Z 0 [Note] - '::' resolves to '::'; 2020-08-05T07:07:20.406018Z 0 [Note] Server socket created on IP: '::'. 2020-08-05T07:07:20.471375Z 0 [Note] Event Scheduler: Loaded 0 events 2020-08-05T07:07:20.471641Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections. Version: '5.7.26' socket: '/tmp/mysqld.sock' port: 16008 Source distribution 2020-08-05T07:07:31.464532Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 10068ms. The settings might not be optimal. (flushed=5784 and evicted=0, during the time.) 2 3 4 5 6 7 82020-08-05T07:08:13.440447Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200805 15:08:13 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 97 98 99 1002020-08-05T07:12:12.083704Z 0 [Note] InnoDB: Rollback of trx with id 393530 completed 2020-08-05T07:12:12.083776Z 0 [Note] InnoDB: Rollback of non-prepared transactions completed
可以看到rollback過程用了很久。
感謝各位的閱讀,以上就是“Innodb關鍵特性之怎么實現啟動、關閉和恢復”的內容了,經過本文的學習后,相信大家對Innodb關鍵特性之怎么實現啟動、關閉和恢復這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。