欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Mysql 启动失败 强制修复InnoDB

今天服务器上的Mysql数据库突然出现问题,PHP无法连接Mysql数据库,提示:
ERROR(HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql.socket'(2)


注:做任何操作前建议首先备份数据库......

 

通过在网上查询资料使用下面命令确认服务状态:
/etc/rc.d/init.d/mysqld status
状态为:停止
/etc/rc.d/init.d/mysqld start
执行启动命令服务启动失败。
虽然确认了Mysql服务无法启动。但是一时没找到解决的办法。最后查看到Mysql日志,尝试启动的日志如下:

090921 15:58:48  mysqld started
090921 15:58:48 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090921 15:58:48 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
090921 15:58:48  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...
InnoDB: Error: tried to read 16384 bytes at offset 0 83689472.
InnoDB: Was only able to read -1.
090921 15:59:10  InnoDB: Operating system error number 5 in a file operation.
InnoDB: Error number 5 means 'Input/output error'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.0/en/operating-system-error-codes.html
InnoDB: File operation call: 'read'.
InnoDB: Cannot continue operation.
090921 15:59:10  mysqld ended

日志中
[Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
在网络资料中看到过,既然是Warning应该不会导致服务无法启动。
继续查看日志
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
090921 15:58:48  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...
InnoDB: Error: tried to read 16384 bytes at offset 0 83689472.
InnoDB: Was only able to read -1.

这部分日志内容从网络查看资料应该是 .ibd files 读写错误,对InnoDB还不太了解,经查找资料找到如下方法:
强制修复InnoDB:
在my.ini 的[mysqld]中加入

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=10M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8

innodb_force_recovery = 4

max_allowed_packet=16M

加入以上内容重新尝试启动Mysql,启动成功~!

但是出现了重大问题,用户数据库数据表丢失......还好只是测试用的数据库,可见数据库的备份还是很重要的。

来自 http://blog.sina.com.cn/s/blog_606ac2740100f8nq.html

普通分类: