共計(jì) 7858 個(gè)字符,預(yù)計(jì)需要花費(fèi) 20 分鐘才能閱讀完成。
這篇文章主要講解了“mysql 中 innodb_force_recovery 參數(shù)分析”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著丸趣 TV 小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“mysql 中 innodb_force_recovery 參數(shù)分析”吧!
一、問(wèn)題描述
今天在線運(yùn)行的一個(gè) mysql 崩潰了。
查看錯(cuò)誤日志,如下:
-----------------------------------------
161108 11:36:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
2017-08-15 11:36:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-15 11:36:46 5497 [Note] Plugin FEDERATED is disabled.
2017-08-15 11:36:46 7f11c48e1720 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB s internal memory allocator.
2017-08-15 11:36:46 5497 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-08-15 11:36:46 5497 [Note] InnoDB: The InnoDB memory heap is disabled
2017-08-15 11:36:46 5497 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-08-15 11:36:46 5497 [Note] InnoDB: Memory barrier is not used
2017-08-15 11:36:46 5497 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-08-15 11:36:46 5497 [Note] InnoDB: Using CPU crc32 instructions
2017-08-15 11:36:46 5497 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2017-08-15 11:36:46 5497 [Note] InnoDB: Completed initialization of buffer pool
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 5.
InnoDB: You may have to recover from a backup.
2017-08-15 11:36:46 7f11c48e1720 InnoDB: Page dump in ascii and hex (16384 bytes):
len 16384; hex 7478d078000000050000000000000000000000000f271f4d000700000000000000000000000000000000001b4000000000000000000200f20000000000000006000000000000002d000000000000002e000000000000002f0000000000000030000000000(省略很多類似代碼)InnoDB: End of page dump
2017-08-15 11:36:46 7f11c48e1720 InnoDB: uncompressed page, stored checksum in field1 1954074744, calculated checksums for field1: crc32 993334256, innodb 2046145943, none 3735928559, stored checksum in field2 1139795846, calculated checksums for field2: crc32 993334256, innodb 1606613742, none 3735928559, page LSN 0 254222157, low 4 bytes of LSN at page end 254221236, page number (if stored to page already) 5, space id (if created with = MySQL-4.1.1 and stored already) 0
InnoDB: Page may be a transaction system page
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 5.
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.6/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.
2017-08-15 11:36:46 7f11c48e1720 InnoDB: Assertion failure in thread 139714288817952 in file buf0buf.cc line 4201
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
03:36:46 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.
key_buffer_size=16777216
read_buffer_size=262144
max_used_connections=0
max_threads=1000
thread_count=0
connection_count=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 798063 K bytes of memory
Hope that s ok; if not, decrease some variables in the equation.
Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/local/mysql/bin/mysqld(my_print_stacktrace+0x35)[0x8e64b5]
/usr/local/mysql/bin/mysqld(handle_fatal_signal+0x41b)[0x652fbb]
/lib64/libpthread.so.0(+0xf7e0)[0x7f11c44c77e0]
/lib64/libc.so.6(gsignal+0x35)[0x7f11c315d625]
/lib64/libc.so.6(abort+0x175)[0x7f11c315ee05]
/usr/local/mysql/bin/mysqld[0xa585c5]
/usr/local/mysql/bin/mysqld[0xa6c7b4]
/usr/local/mysql/bin/mysqld[0xa6cbc7]
/usr/local/mysql/bin/mysqld[0xa5bce2]
/usr/local/mysql/bin/mysqld[0xa1e2ba]
/usr/local/mysql/bin/mysqld[0xa0bf60]
/usr/local/mysql/bin/mysqld[0x95a427]
/usr/local/mysql/bin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x48)[0x58f788]
/usr/local/mysql/bin/mysqld[0x6e4a36]
/usr/local/mysql/bin/mysqld(_Z11plugin_initPiPPci+0xb3e)[0x6e826e]
/usr/local/mysql/bin/mysqld[0x582d85]
/usr/local/mysql/bin/mysqld(_Z11mysqld_mainiPPc+0x4d8)[0x587d18]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x7f11c3149d5d]
/usr/local/mysql/bin/mysqld[0x57a019]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
161108 11:36:46 mysqld_safe mysqld from pid file /usr/local/mysql/var/VM_241_49_centos.pid ended
------------------------------------------------------------------------------
二、問(wèn)題分析
從日志中可以看出是 innodb 引擎出了問(wèn)題。日志里提示到
http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
查看強(qiáng)制恢復(fù)的方法。在 mysql 的配置文件 my.cnf 里找到 [mysqld]字段下,添加 innodb_force_recovery=1:
[mysqld]innodb_force_recovery = 1
如果 innodb_force_recovery = 1 不生效,則可嘗試 2——6 幾個(gè)數(shù)字
然后重啟 mysql,重啟成功。然后使用 mysqldump 或 pma 導(dǎo)出數(shù)據(jù),執(zhí)行修復(fù)操作等。修復(fù)完成后,把該參數(shù)注釋掉,還原默認(rèn)值 0。
配置文件的參數(shù):innodb_force_recovery
innodb_force_recovery 影響整個(gè) InnoDB 存儲(chǔ)引擎的恢復(fù)狀況。默認(rèn)為 0,表示當(dāng)需要恢復(fù)時(shí)執(zhí)行所有的恢復(fù)操作(即校驗(yàn)數(shù)據(jù)頁(yè) /purge undo/insert buffer merge/rolling back forward),當(dāng)不能進(jìn)行有效的恢復(fù)操作時(shí),mysql 有可能無(wú)法啟動(dòng),并記錄錯(cuò)誤日志;
innodb_force_recovery 可以設(shè)置為 1 -6, 大的數(shù)字包含前面所有數(shù)字的影響。當(dāng)設(shè)置參數(shù)值大于 0 后,可以對(duì)表進(jìn)行 select,create,drop 操作, 但 insert,update 或者 delete 這類操作是不允許的。
1(SRV_FORCE_IGNORE_CORRUPT): 忽略檢查到的 corrupt 頁(yè)。
2(SRV_FORCE_NO_BACKGROUND): 阻止主線程的運(yùn)行,如主線程需要執(zhí)行 full purge 操作,會(huì)導(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 存儲(chǔ)引擎會(huì)將未提交的事務(wù)視為已提交。
6(SRV_FORCE_NO_LOG_REDO): 不執(zhí)行前滾的操作。
三、解析方案
一般修復(fù)方法參考:
第一種方法
建立一張新表:
create table demo_bak #和原表結(jié)構(gòu)一樣,只是把 INNODB 改成了 MYISAM。
把數(shù)據(jù)導(dǎo)進(jìn)去
insert into demo_bak select * from demo;
刪除掉原表:
drop table demo;
注釋掉 innodb_force_recovery 之后,重啟。
重命名:
rename table demo_bak to demo;
最后改回存儲(chǔ)引擎:
alter table demo engine = innodb
第二種方法
另一個(gè)方法是使用 mysqldump 將表格導(dǎo)出,然后再導(dǎo)回到 InnoDB 表中。這兩種方法的結(jié)果是相同的。
備份導(dǎo)出 (包括結(jié)構(gòu)和數(shù)據(jù)):
mysqldump -uroot -p123 test test.sql
還原方法 1:
use test;
source test.sql
還原方法 2(系統(tǒng)命令行):
mysql -uroot -p123 test test.sql;
注意,CHECK TABLE 命令在 InnoDB 數(shù)據(jù)庫(kù)中基本上是沒(méi)有用的。
第三種方法 1、配置 my.cnf
配置 innodb_force_recovery = 1 或 2——6 幾個(gè)數(shù)字,重啟 MySQL
2、導(dǎo)出數(shù)據(jù)腳本
mysqldump -uroot -p123 test test.sql
導(dǎo)出 SQL 腳本。或者用 Navicat 將所有數(shù)據(jù)庫(kù) / 表導(dǎo)入到其他服務(wù)器的數(shù)據(jù)庫(kù)中。
注意:這里的數(shù)據(jù)一定要備份成功。然后刪除原數(shù)據(jù)庫(kù)中的數(shù)據(jù)。
3、刪除 ib_logfile0、ib_logfile1、ibdata1
備份 MySQL 數(shù)據(jù)目錄下的 ib_logfile0、ib_logfile1、ibdata1 三個(gè)文件,然后將這三個(gè)文件刪除
4、配置 my.cnf
將 my.cnf 中 innodb_force_recovery = 1 或 2——6 幾個(gè)數(shù)字這行配置刪除或者配置為 innodb_force_recovery = 0,重啟 MySQL 服務(wù)
5、將數(shù)據(jù)導(dǎo)入 MySQL 數(shù)據(jù)庫(kù)
mysql -uroot -p123 test test.sql; 或者用 Navicat 將備份的數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)中。
此種方法下要注意的問(wèn)題:
1、ib_logfile0、ib_logfile1、ibdata1 這三個(gè)文件一定要先備份后刪除;
2、一定要確認(rèn)原數(shù)據(jù)導(dǎo)出成功了
3、當(dāng)數(shù)據(jù)導(dǎo)出成功后,刪除原數(shù)據(jù)庫(kù)中的數(shù)據(jù)時(shí),如果提示不能刪除,可在命令行進(jìn)入 MySQL 的數(shù)據(jù)目錄,手動(dòng)刪除相關(guān)數(shù)據(jù)庫(kù)的文件夾或者數(shù)據(jù)庫(kù)文件夾下的數(shù)據(jù)表文件,前提是數(shù)據(jù)一定導(dǎo)出或備份成功。
感謝各位的閱讀,以上就是“mysql 中 innodb_force_recovery 參數(shù)分析”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì) mysql 中 innodb_force_recovery 參數(shù)分析這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!