Mysql8斷電崩潰解決

一、概述

單機Mysql8數據庫服務器運行過程中突然斷電,導致數據庫崩潰,無法重啟。

二、查找原因

查看mysql運行錯誤日志:WIN-SOTMI68HRV6.err (在Data目錄下)

InnoDB: End of page dump
InnoDB: Page may be a system page
2023-02-01T09:31:02.878917Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2023-02-01T09:31:02.882631Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.23) starting as process 3496
2023-02-01T09:31:02.923391Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-01T09:31:05.964384Z 1 [ERROR] [MY-011971] [InnoDB] Tablespace 'innodb_system' Page [page id: space=0, page number=5] log sequence number 3275776865 is in the future! Current system log sequence number 3197057036.
2023-02-01T09:31:05.966225Z 1 [ERROR] [MY-011972] [InnoDB] Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html for information about forcing recovery.
2023-02-01T09:31:05.98

InnoDB: End of page dump
InnoDB: Page may be a system page
2023-02-01T11:03:39.767939Z 1 [ERROR] [MY-011906] [InnoDB] Database page corruption on disk or a failed file read of page [page id: space=4294967278, page number=101]. You may have to recover from a backup.
 len 16384; hex 4359822100000065000000000000000000000000c340647700060000000000000000ffffffeefffffffe0000000000000000ffffffff0000ffffffff0000ffffffee000000580932000000d600000154fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

很明顯[ERROR] ,找不到磁盤文件。通過上述日志可以得知:數據庫出現錯誤,無法重啟。

原因:為瞭保護數據,InnoDB使用校驗和(與頁儲存在一起)。當InnoDB從磁盤讀取時,它計算每個頁的校驗和,並與磁盤加載的校驗和進行比較。如果值是不同的,可能真的發生瞭一些錯誤。InnoDB將關閉MySQL服務器,以防止進一步的邏輯或物理損壞。

三、解決方案

1.如何找出損壞發生的原因

沒有通用的解決方案。最典型的是有一些硬件問題,例如:物理磁盤或內存故障,壞的驅動器/控制器,甚至操作系統內核的bug。下面是一些建議:

在Linux平臺上,有時會重置頁緩存能解決這個問題:

echo 2 > /proc/sys/vm/drop_caches

檢查系統日志有沒有可能的硬件故障。
如果InnoDB每次在特定頁崩潰,最典型的是物理磁盤發生故障:運行對於你的OS /硬件的詳細磁盤診斷。
如果崩潰是隨機的且不在相同查詢重復,可能是RAM故障:運行詳細的RAM診斷。
在MySQL關閉時,用innochecksum工具檢查InnoDB文件是有幫助的。

作者這裡故障原因是斷電導致數據出現問題,隻能重裝Mysql。

2.如何從損壞中恢復

最重要的是執行詳細的硬件診斷,以消除問題擴散的機會。如果操作系統I / O緩存是磁盤讀損壞的原因,重置緩存或重新啟動操作系統應有助於消除當前的問題,數據庫可能會重新運作。
有時唯一的解決辦法是在有效恢復模式下備份數據。

筆者後面嘗試強制啟動,可以啟動Mysql,但是數據庫隻能讀不能寫,通過日志又找不到損壞的數據表,無奈,隻能先備份數據庫,然後重裝Mysql。

修改數據庫,一直報錯:

running in read_only mode 1836

將mysql改為強制啟動:

在my.ini中【mysqld】節點下加上

innodb_force_recovery=0

然後對數據庫進行備份。
備份方式:

一、數據庫備份

第一種:(cmd窗口使用)
在命令提示符用mysqldump命令行備份數據庫。
命令格式
mysqldump -u用戶名 -p 數據庫名 > 保存名.sql
范例:

mysqldump -uroot -p dataname > d:\data.sql

(導出數據庫dataname到data.sql文件)
提示輸入密碼時,輸入該數據庫用戶名的密碼。

第二種:指定導出備份編碼

mysqldump -u root -p密碼 --default-character-set=數據編碼 數據庫名稱> data.sql

案例:

mysqldump -u root -p123456 --default-character-set=utf8 discuss_chi>d:/data.sql

mySQL數據庫在windows環境下備份與恢復:

二,恢復數據庫,一共二種方式。

第一種;定義還原編碼類型(cmd窗使用)
定義編碼導入:

mysql -u root -p --default-character-set=utf8 -f dataname<d:/dis.sql

如果亂碼使用二進導入

mysql -u root -p --default-character-set=binary -f dataname<d:/dis.sql

第二種:
source 命令(mysql控制臺窗口使用)
進入mysql數據庫控制臺,

如在運行中輸入:mysql -u root -p

mysql>use databasename;

1、確定數據庫默認編碼,比如編碼為gbk,將讀入途徑編碼同樣設為gbk,命令為:
set names gbk;(導入數據出現亂碼的時候用平常不用)
2、然後使用source命令,後面參數為腳本文件(如這裡用到的.sql)

mysql>source d:\data.sql;

備份後,重裝Mysql,恢復數據庫。

到此這篇關於Mysql8斷電崩潰解決的文章就介紹到這瞭,更多相關Mysql8斷電崩潰內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: