問題
MySQL自3.23.58版本以后,提供了名為InnoDB的引擎提供存儲過程等功能
當服務器發生意外斷電等錯誤的時候,可能導致innodb鎖死
用top命令查看,發現mysqld進程占用cpu達到100%並無法正常啟動、關閉
070316 12:30:43 mysqld started
070316 12:30:43 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...
070316 12:30:43 InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 0 2347685.
InnoDB: Doing recovery: scanned up to log sequence number 0 2347685
070316 12:30:43 InnoDB: Error: page 4 log sequence number 0 1516429185
InnoDB: is in the future! Current system log sequence number 0 2347685.
InnoDB: Your database may be corrupt.
解決方案
首先要徹底殺掉所有運行的mysql進程,並暫時停止web服務器,以免再次出發mysql的調用
/etc/init.d/httpd stop
killall -9 mysqld
killall -9 mysqld_safe
現在用ps awxuf命令確認沒有mysql相關進程在運行了
到/var/lib/mysql目錄下,找到ibdata1、ib_logfile0、ib_logfile1等幾個文件,將其改名或者移動走
執行/etc/init.d/mysqld restart重新啟動mysqld
這時候再查看log,就會發現innodb的引擎會重建出錯的文件
070316 12:41:35 mysqld started
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
070316 12:41:35 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
070316 12:41:35 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
070316 12:41:35 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
070316 12:41:36 InnoDB: Started; log sequence number 0 0
/usr/libexec/mysqld: ready for connections.
Version: '4.1.12' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
現在可以通過top命令確認mysqld是否正常運行。
執行/etc/init.d/httpd start正常啟動web服務,並觀察mysql是否正常,一般故障可以解決
注意:如果想禁用innodb的功能,可以在/etc/my.cnf里邊的[mysqld]部分中,加入如下一行:
skip-innodb
然后重啟mysqld服務,即可禁用innodb 。
但是不推薦禁用,如果部分mysql程序調用了存儲過程,那么就無法工作了。
