共計 2776 個字符,預計需要花費 7 分鐘才能閱讀完成。
這篇文章主要講解了“mysql innodb 異常如何處理”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“mysql innodb 異常如何處理”吧!
一、回退重新裝 mysql
為避免再從其他地方導入這個數據的麻煩,先對當前庫的數據庫文件做了個備份(/var/lib/mysql/ 位置)。接下來將 Percona server 5.7 包進行了卸載,重新安裝原先老的 5.1.71 的包,啟動 mysql 服務,提示 Unknown/unsupported table type: innodb,無法正常啟動。
110509 12:04:27 InnoDB: Initializing buffer pool, size = 384.0M
110509 12:04:27 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 157286400 bytes!
110509 12:04:27 [ERROR] Plugin InnoDB init function returned error.
110509 12:04:27 [ERROR] Plugin InnoDB registration as a STORAGE ENGINE failed.
110509 12:04:27 [ERROR] Unknown/unsupported table type: innodb
110509 12:04:27 [ERROR] Aborting
110509 12:04:27 [Note] /usr/sbin/mysqld: Shutdown complete
刪除 /var/lib/mysql/ 目錄,重新啟動數據庫服務,并初始化,發現正常,show engines 能發現有 innodb 引擎。再將數據庫停掉,將之前備份的 /var/lib/mysql/ 目錄的內容覆蓋當前位置的內容,重啟。又發現不能進行啟動,報錯內容和剛剛一樣。
/var/lib/mysql 目錄內容的結構如下:
-rw-rw---- 1 mysql mysql 10485760 2 月 26 18:10 ibdata1
-rw-rw---- 1 mysql mysql 5242880 2 月 26 18:10 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 2 月 26 17:20 ib_logfile1
drwx------ 2 mysql mysql 4096 2 月 26 17:20 mysql
drwx------ 2 mysql mysql 4096 2 月 26 17:24 wiki
wiki 目錄是測試數據的庫,ibdata1 文件為數據文件,ib 開頭的兩個文件為日志文件,mysql 目錄下為系統庫相關的東西。再次使用初始化的數據,并將 wiki 目錄和 ibdata1 文件覆蓋到 /var/lib/mysql 目錄下,可以正常啟動,也可以正常登錄。
二、innodb 模塊重裝
不過在通過 mysqldump 備份時,又提示 unknow table engine“Innodb”。登錄后,查看當前所有的引擎類型,發現其中果然不存在 innodb 類型:
通過 alter 命令修改其中一個表的類型為 MyISAM,發現仍然報錯。
通過 find 查找發現 /usr/lib64/mysql/plugin/ 目錄下有 ha_innodb_plugin.so 文件。印象中 mysql5 以后的版本支持在線插件安裝。通過下面查看確認,果然支持:
使用如下命令加載時,發現不成功:
install plugin innodb soname ha_innodb.so
三、備份
在 /etc/my.cnf 中增加如下配置:
plugin-load=innodb=ha_innodb_plugin.so
plugin_dir=/usr/lib64/mysql/plugin/
default-storage-engine=InnoDB
發現仍啟動失敗。查看 mysql-error.log 發現有如下內容:
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: See also http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
打開 forcing-innodb-recovery 官方頁面,發現可以通過指定 innodb_force_recovery 參數,進行強制啟動和恢復。在 /etc/my.cnf 中增加如下內容:
innodb_force_recovery=6
重新啟動成功了。通過 mysqldump 備份也沒有問題,將備份數據導入其他主機發現也正常可以測試。
這下就好搞了,將 mysql 徹底刪除,重新安裝 Percona server 5.7,安裝完后,建庫,還原數據,程序重新連接,一切 OK。
感謝各位的閱讀,以上就是“mysql innodb 異常如何處理”的內容了,經過本文的學習后,相信大家對 mysql innodb 異常如何處理這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!
向 AI 問一下細節
丸趣 TV 網 – 提供最優質的資源集合!