偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

MySQL斷電恢復(fù)的一點簡單分析

數(shù)據(jù)庫 MySQL
我首先是要確認是否為線上業(yè)務(wù)還是測試環(huán)境,線上業(yè)務(wù)來說這個影響還是很大的。如果數(shù)據(jù)庫無法啟動,首要任務(wù)還是把數(shù)據(jù)庫啟動,然后在這個基礎(chǔ)上查看丟失的數(shù)據(jù)程度,安排數(shù)據(jù)修復(fù)的事宜。

[[205074]]

今天有個網(wǎng)友問我一個MySQL的恢復(fù)問題。提供的截圖如下。

 

對于這個問題,在一些斷電的場景下還是可能出現(xiàn)的。我首先是要確認是否為線上業(yè)務(wù)還是測試環(huán)境,線上業(yè)務(wù)來說這個影響還是很大的。如果數(shù)據(jù)庫無法啟動,首要任務(wù)還是把數(shù)據(jù)庫啟動,然后在這個基礎(chǔ)上查看丟失的數(shù)據(jù)程度,安排數(shù)據(jù)修復(fù)的事宜。

當(dāng)然從我的角度來說,怎么去快速復(fù)現(xiàn)這個問題呢。我用自己寫的快速搭建測試主從環(huán)境的腳本(https://github.com/jeanron100/mysql_slaves,后期有一位大牛建議用Python來做,最近在考慮),分分鐘即可搞定。

我們創(chuàng)建一個表test,指定id,name兩個字段。然后開啟顯式事務(wù)。

  1. create table test(id int primary key,name varchar(30) not null); 

顯式開啟一個事務(wù):

  1. begin
  2. insert into test values(1,'a'); 
  3. insert into test values(2,'b'); 
  4. insert into test values(3,'c');  

不提交,我們直接查看mysql的服務(wù)進程,直接Kill掉。默認情況下雙1指標是開啟的,我們直接模擬斷電重啟,看看后臺的處理情況:

  1. 2017-09-13 15:05:11 35556 [Note] InnoDB: Highest supported file format is Barracuda. 
  2.  
  3. 2017-09-13 15:05:11 35556 [Note] InnoDB: The log sequence numbers 1625987 and 1625987 in ibdata files do not match the log sequence number 1640654 in the ib_logfiles! 
  4.  
  5. 2017-09-13 15:05:11 35556 [Note] InnoDB: Database was not shutdown normally! 
  6.  
  7. 2017-09-13 15:05:11 35556 [Note] InnoDB: Starting crash recovery. 
  8.  
  9. 2017-09-13 15:05:11 35556 [Note] InnoDB: Reading tablespace information from the .ibd files... 
  10.  
  11. 2017-09-13 15:05:11 35556 [Note] InnoDB: Restoring possible half-written data pages 
  12.  
  13. 2017-09-13 15:05:11 35556 [Note] InnoDB: from the doublewrite buffer... 
  14.  
  15. InnoDB: 1 transaction(s) which must be rolled back or cleaned up 
  16.  
  17. InnoDB: in total 3 row operations to undo 
  18.  
  19. InnoDB: Trx id counter is 2304 
  20.  
  21. 2017-09-13 15:05:11 35556 [Note] InnoDB: 128 rollback segment(s) are active. 
  22.  
  23. InnoDB: Starting in background the rollback of uncommitted transactions 
  24.  
  25. 2017-09-13 15:05:11 7f5ccc3d1700 InnoDB: Rolling back trx with id 1806, 3 rows to undo 
  26.  
  27. 2017-09-13 15:05:11 35556 [Note] InnoDB: Rollback of trx with id 1806 completed 
  28.  
  29. 2017-09-13 15:05:11 7f5ccc3d1700 InnoDB: Rollback of non-prepared transactions completed 
  30.  
  31. 2017-09-13 15:05:11 35556 [Note] InnoDB: Waiting for purge to start 
  32.  
  33. 2017-09-13 15:05:11 35556 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.14-rel62.0 started; log sequence number 1640654 
  34.  
  35. 2017-09-13 15:05:11 35556 [Note] Recovering after a crash using binlog 
  36.  
  37. 2017-09-13 15:05:11 35556 [Note] Starting crash recovery... 
  38.  
  39. 2017-09-13 15:05:11 35556 [Note] Crash recovery finished.  

可以看到后臺檢測到了上次的異常宕機,然后開啟崩潰恢復(fù),InnoDB檢測到日志LSN是1625987 而系統(tǒng)數(shù)據(jù)文件ibd的LSN為1625987 ,和ib_logfiles里面的LSN不匹配。后面就是一系列的恢復(fù),前滾,恢復(fù),回滾。***表里的數(shù)據(jù)為空,證明之前的事務(wù)都已經(jīng)回滾了。

所以基于上面的情況,我們明白開啟了事務(wù),基本情況下這個問題是不會出現(xiàn)的,什么時候會拋出開始的錯誤呢。

我們繼續(xù)測試,開啟一個顯式事務(wù),不提交。

  1. begin
  2.  
  3. insert into test values(1,'a'); 
  4.  
  5. insert into test values(2,'b'); 
  6.  
  7. insert into test values(3,'c');  

然后殺掉mysql的服務(wù)進程,找到mysql的數(shù)據(jù)目錄下,刪除redo文件。完成后我們重啟數(shù)據(jù)庫。

這個時候就拋出了和截圖類似的錯誤。

  1. 2017-09-13 16:05:14 36896 [Note] InnoDB: Highest supported file format is Barracuda. 
  2.  
  3. 2017-09-13 16:05:14 7f73450a97e0 InnoDB: Error: page 7 log sequence number 1627722 
  4.  
  5. InnoDB: is in the future! Current system log sequence number 1626124. 
  6.  
  7. InnoDB: Your database may be corrupt or you may have copied the InnoDB 
  8.  
  9. InnoDB: tablespace but not the InnoDB log files. See 
  10.  
  11. InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html 
  12.  
  13. InnoDB: for more information.  

這個問題目前的影響范圍其實還不明顯,因為盡管如此,我們還是能夠?qū)懭霐?shù)據(jù)的。 

  1. mysql> insert into test values(1,'a'); 
  2.  
  3. Query OK, 1 row affected (0.04 sec) 
  4.  
  5. mysql> select *from test; 
  6.  
  7. +----+------+ 
  8.  
  9. | id | name | 
  10.  
  11. +----+------+ 
  12.  
  13. | 1 | a | 
  14.  
  15. +----+------+ 
  16.  
  17. 1 row in set (0.00 sec)  

關(guān)于崩潰恢復(fù),有一個數(shù)據(jù)參數(shù)尤其需要注意,那就是innodb_force_recovery,這個參數(shù)默認值為0,如果為非0的值(范圍為1-6),會有下面的影響范圍。

1 (SRV_FORCE_IGNORE_CORRUPT): 忽略檢查到的corrupt頁。

2 (SRV_FORCE_NO_BACKGROUND): 阻止主線程的運行,如主線程需要執(zhí)行full purge操作,會導(dǎo)致crash。

3 (SRV_FORCE_NO_TRX_UNDO): 不執(zhí)行事務(wù)回滾操作。

4 (SRV_FORCE_NO_IBUF_MERGE): 不執(zhí)行插入緩沖的合并操作。

5 (SRV_FORCE_NO_UNDO_LOG_SCAN):不查看重做日志,InnoDB存儲引擎會將未提交的事務(wù)視為已提交。

6 (SRV_FORCE_NO_LOG_REDO): 不執(zhí)行前滾的操作。

當(dāng)然這個參數(shù)的設(shè)置修改是需要重啟MySQL服務(wù)的。

  1. mysql> set global innodb_force_recovery=2; 
  2.  
  3. ERROR 1238 (HY000): Variable 'innodb_force_recovery' is a read only variable  

在此假設(shè)我們設(shè)置為2,再次復(fù)現(xiàn)這個問題問題,你就會發(fā)現(xiàn),數(shù)據(jù)庫暫時是可以啟動的,但是數(shù)據(jù)只能查詢,DML操作都會拋錯。

  1. mysql> select *from test; 
  2.  
  3. Empty set (0.00 sec) 
  4.  
  5. mysql> 
  6.  
  7. mysql> insert into test values(1,'a'); 
  8.  
  9. ERROR 1030 (HY000): Got error -1 from storage engine  

按照這個影響的范圍來評估force_recovery的值,我們就可以做相應(yīng)的取舍了。如果MySQL服務(wù)無法正常啟動,就可以修改這個參數(shù)值來調(diào)整,先滿足服務(wù)可持續(xù)性的基本問題。然后評估后導(dǎo)出重要的數(shù)據(jù)來。 

責(zé)任編輯:龐桂玉 來源: 楊建榮的學(xué)習(xí)筆記
相關(guān)推薦

2013-01-08 10:06:43

創(chuàng)業(yè)創(chuàng)業(yè)方法

2016-04-05 10:12:58

HiveSQLHadoop

2011-07-12 17:55:28

尾日志備份

2009-11-09 13:56:15

WCF Stream對

2010-05-20 15:29:43

優(yōu)化IIS

2011-11-30 09:26:25

項目管理

2012-03-27 08:49:19

Json

2009-07-09 15:09:05

JDK卸載

2009-09-14 19:44:27

LINQ To SQL

2024-05-31 08:40:09

2020-11-26 10:16:31

MIUI廣告

2025-05-29 00:00:00

UI 庫前端模塊化

2011-12-02 09:39:22

項目管理

2012-11-23 16:46:12

LinuxVim

2009-09-14 20:17:05

并行LINQ

2014-06-04 10:48:38

Swift蘋果iOS

2012-07-12 10:49:53

項目管理

2011-07-04 09:33:04

惠普轉(zhuǎn)型李艾科

2016-01-06 09:49:59

青云/SDN

2011-03-15 10:41:05

內(nèi)部類
點贊
收藏

51CTO技術(shù)棧公眾號