mysql服务器断电引起的风波

我在虚拟机上模拟mysql服务器突然断电的场景,在mysql正常运行的情况下直接重启服务器,结果mysql数据库起不来了,详细情况如下:

环境:

操作系统           系统内核版本                                  mysql 版本

CentOS 5.4       Linux  2.6.18-164.el5  x86_64        5.6.14

 

1. 重启服务器后(模拟断电),启动mysql报错

[root@langkeziju2 bin]# ./mysqld_safe --user=mysql &
131104 10:02:26 mysqld_safe Logging to '/data0/mysql-3307/data/langkeziju2.err'.
131104 10:02:26 mysqld_safe Starting mysqld daemon with databases from /data0/mysql-3307/data
131104 10:02:28 mysqld_safe mysqld from pid file /data0/mysql-3307/data/langkeziju2.pid ended

 

2.在错误日志中查看究竟

[root@langkeziju2 bin]# vi  /data0/mysql-3307/data/langkeziju2.err

2013-11-04 10:02:27 5816 [Note] InnoDB: The InnoDB memory heap is disabled
2013-11-04 10:02:27 5816 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-11-04 10:02:27 5816 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-11-04 10:02:27 5816 [Note] InnoDB: Using Linux native AIO
2013-11-04 10:02:27 5816 [Note] InnoDB: Using CPU crc32 instructions
2013-11-04 10:02:27 5816 [Note] InnoDB: Initializing buffer pool, size = 100.0M
2013-11-04 10:02:27 5816 [Note] InnoDB: Completed initialization of buffer pool
2013-11-04 10:02:28 5816 [Note] InnoDB: Highest supported file format is Barracuda.
2013-11-04 10:02:28 5816 [Note] InnoDB: The log sequence numbers 1600657 and 1600657 in ibdata files do not match the log sequence number 1676012 in the ib_logfiles!
2013-11-04 10:02:28 5816 [Note] InnoDB: Database was not shutdown normally!
2013-11-04 10:02:28 5816 [Note] InnoDB: Starting crash recovery.
2013-11-04 10:02:28 5816 [Note] InnoDB: Reading tablespace information from the .ibd files...
2013-11-04 10:02:28 5816 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace hr/employee uses space ID: 1 at filepath: ./hr/employee.ibd. Cannot open tablespace mysql/innodb_table_stats which uses space ID: 1 at filepath: ./mysql/innodb_table_stats.ibd
2013-11-04 10:02:28 2aaf5d032520  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./mysql/innodb_table_stats.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.

131104 10:02:28 mysqld_safe mysqld from pid file /data0/mysql-3307/data/langkeziju2.pid ended

hr/employee 表空间id号(1)抢占了mysql/innodb_table_stats表空间的id号(1),导致不能打开mysql/innodb_table_stats表空间,从而数据库不能打开

 

3. 根据错误日志中的提示将innodb_force_recovery参数设置成>0的数值加入配置文件my.cnf中

[root@langkeziju2 bin]# vi /data0/mysql-3307/my.cnf

在[mysqld]组中加入:

innodb_force_recovery=6

 

*************************************

innodb_force_recovery参数解释:

innodb_force_recovery影响整个InnoDB存储引擎的恢复状况,默认值为0,表示当需要恢复时执行所有的恢复操作。
当不能进行有效的恢复操作时,mysql有可能无法启动,并记录下错误日志。

innodb_force_recovery可以设置为1-6,大的数字包含前面所有数字的影响。
当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作是不允许的。

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):不执行前滚的操作。

*********************************

 

4.mysql能正常启动了,我对hr库做了备份,然后将其删掉

[root@langkeziju2 bin]# ./mysqld_safe --user=mysql &
[1] 6440
[root@langkeziju2 bin]# 131104 10:04:06 mysqld_safe Logging to '/data0/mysql-3307/data/langkeziju2.err'.
131104 10:04:06 mysqld_safe Starting mysqld daemon with databases from /data0/mysql-3307/data

 

[root@langkeziju2 data_3307]# mysqldump -uroot -p hr > /bak/hr.sql
Enter password:

[root@langkeziju2 data_3307]# ls
hr.sql

 


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hr                 |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database hr;
Query OK, 3 rows affected (0.65 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

 

5. 还原hr库,报:ERROR 1030 (HY000) at line 41: Got error -1 from storage engine

[root@langkeziju2 data_3307]# mysql -uroot -p hr < hr.sql
Enter password:
ERROR 1049 (42000): Unknown database 'hr.sql'

还原hr库,hr库必须存在,因我已经将hr库删除,现在创建一个空hr库

mysql> create database hr;
Query OK, 1 row affected (0.00 sec)

再次尝试还原hr库

[root@langkeziju2 data_3307]# mysql -uroot -p hr < hr.sql
Enter password:
ERROR 1030 (HY000) at line 41: Got error -1 from storage engine

报这个错误是因为上面在my.cnf中添加了innodb_force_recovery=6的缘故

 

6. 将my.cnf中的innodb_force_recovery参数设置成0或者将其删除

[root@langkeziju2 ~]# vi /data0/mysql-3307/my.cnf

[mysqld]

innodb_force_recovery=0

 

7.重启mysql

[root@langkeziju2 ~]# mysqladmin -uroot -p shutdown

[root@langkeziju2 ~]# mysqld_safe --user=mysql &

 

8. 成功还原hr库

[root@langkeziju2 data_3307]# mysql3307 hr < hr.sql
Enter password:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hr                 |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.12 sec)

 

发布了52 篇原创文章 · 获赞 18 · 访问量 34万+
展开阅读全文

服务器断电mysql无法启动

05-20

因意外导致服务器断电,重启后发现mysql起不来了 ``` [root@cacti ~]# service mysqld restart 停止 mysqld: [确定] MySQL Daemon failed to start. 正在启动 mysqld: [失败] ``` 查看日志: ``` [root@cacti ~]# tail -100 /var/log/mysqld.log 150520 12:21:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 150520 12:21:12 InnoDB: Initializing buffer pool, size = 8.0M 150520 12:21:12 InnoDB: Completed initialization of buffer pool InnoDB: Log scan progressed past the checkpoint lsn 2 1552263436 150520 12:21:12 InnoDB: Database was not shut down normally! InnoDB: Starting crash recovery. InnoDB: Reading tablespace information from the .ibd files... InnoDB: Restoring possible half-written data pages from the doublewrite InnoDB: buffer... 150520 12:21:12 InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percents: 0 1 2 3 4 5 6 7 8 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 InnoDB: Database page corruption on disk or a failed InnoDB: file read of page 206. InnoDB: You may have to recover from a backup. 150520 12:21:12 InnoDB: Page dump in ascii and hex (16384 bytes): len 16384; hex cc507667000000ce0000000000000000000000025cabb0bc000200000000000000000000000000021e751eb0ffffffff0000ffffffff000000021dbb0000000000000002123200000001000000ce002c000000ce002c000000000304a196000000000304a1970001011000000000000000000000014....... .... .... .... oDB: End of page dump 150520 12:21:12 InnoDB: Page checksum 3392922109, prior-to-4.0.14-form checksum 1831220034 InnoDB: stored checksum 3427825255, prior-to-4.0.14-form stored checksum 2455963898 InnoDB: Page lsn 2 1554755772, low 4 bytes of lsn at page end 1556408857 InnoDB: Page number (if stored to page already) 206, InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 0 InnoDB: Page may be an update undo log page InnoDB: Database page corruption on disk or a failed InnoDB: file read of page 206. 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 InnoDB: about forcing recovery. InnoDB: Ending processing because of a corrupt database page. 150520 12:21:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended ``` mysql新手一个,希望大家能帮帮忙分析下,谢谢! 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览