やったこと

webサービスを作るときに考えたことを垂れ流します

MySQLをインストールしたけどなかなか起動できない

webサーバ(CentOS6.3)にMySQLをインストールしたんだけどなかなか起動できない。

mysql startを実行しても以下のように失敗してしまう。

#/etc/init.d/mysqld start

MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

/var/log/mysqld.logの中身を見てみると、以下のようなエラーログが出力されてた。

140812 14:47:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140812 14:47:43 [Note] Plugin 'FEDERATED' is disabled.
140812 14:47:43 InnoDB: The InnoDB memory heap is disabled
140812 14:47:43 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140812 14:47:43 InnoDB: Compressed tables use zlib 1.2.3
140812 14:47:43 InnoDB: Using Linux native AIO
140812 14:47:43 InnoDB: Initializing buffer pool, size = 128.0M
140812 14:47:43 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
140812 14:47:43 [ERROR] Plugin 'InnoDB' init function returned error.
140812 14:47:43 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140812 14:47:43 [ERROR] Unknown/unsupported storage engine: InnoDB
140812 14:47:43 [ERROR] Aborting
140812 14:47:43 [Note] /usr/libexec/mysqld: Shutdown complete
140812 14:47:43 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended


以下のログから、ib_logfile0というファイルが初期サイズである0byteでないせいで怒っている様子。

InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes

以前のバージョンのmysqlのデータが残っていたんだろうか。
/var/lib/mysql/にあるib_logfile0やib_logfile1のファイルをrenameしてみた。

# mv ib_logfile0 ib_logfile0_tes
# mv ib_logfile1 ib_logfile1_tes

そして再度mysqld startを実行してみたが、やはりまだ起動失敗してしまう。。
このときのmysqld.logの出力は以下。

140812 15:14:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140812 15:14:27 [Note] Plugin 'FEDERATED' is disabled.
140812 15:14:27 InnoDB: Compressed tables use zlib 1.2.3
140812 15:14:27 InnoDB: Using Linux native AIO
140812 15:14:27 InnoDB: Initializing buffer pool, size = 128.0M
140812 15:14:27 InnoDB: Completed initialization of buffer pool
140812 15:14:27 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
140812 15:14:27  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...
140812 15:14:27  InnoDB: Waiting for the background threads to start
140812 15:14:28 InnoDB: 5.5.39 started; log sequence number 2705932
140812 15:14:28  InnoDB: Warning: table 'mysql/innodb_table_stats'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:14:28  InnoDB: Warning: table 'mysql/innodb_index_stats'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:14:28  InnoDB: Warning: table 'kabulog/wp_options'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:14:28 [ERROR] /usr/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
140812 15:14:28 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
140812 15:14:28 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

以下のログに注目、host.frmというファイルが見つからずに怒っている様子。

140812 15:14:28 [ERROR] /usr/libexec/mysqld: Can't find file: './mysql/host.frm' 

/var/lib/mysql/mysql/を探してみたら、host.frmというファイルがあった。実行権限をみるとrootになっている。この権限はmysqlにするのが正しいらしいので変更する。

#chown -R mysql:mysql host.frm
#chown -R mysql:mysql host.MYD
#chown -R mysql:mysql host.MYI
(この3つのファイルの権限をrootに変更)
#ls
-rw-rw---- 1 mysql mysql   9510 Aug 12 14:58 host.frm
-rw-rw---- 1 mysql mysql      0 Aug 12 14:58 host.MYD
-rw-rw---- 1 mysql mysql   2048 Aug 12 14:58 host.MYI

もういちどmysqlを実行、しかしまだまだ起動失敗してしまう。
このときのエラーログは以下。

"/var/log/mysqld.log" 288L, 17418C
InnoDB: the log sequence number in the ib_logfiles!
140812 15:23:10  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...
140812 15:23:10  InnoDB: Waiting for the background threads to start
140812 15:23:11 InnoDB: 5.5.39 started; log sequence number 2705932
140812 15:23:11  InnoDB: Warning: table 'mysql/innodb_table_stats'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:23:11  InnoDB: Warning: table 'mysql/innodb_index_stats'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:23:11  InnoDB: Warning: table 'kabulog/wp_options'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:23:11  InnoDB: Warning: table 'kabulog/wp_posts'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:23:11  InnoDB: Warning: table 'kabulog/wp_postmeta'
InnoDB: in InnoDB data dictionary has unknown flags 50.
140812 15:23:11 [ERROR] /usr/libexec/mysqld: Incorrect information in file: './mysql/proxies_priv.frm'
140812 15:23:11 [ERROR] Fatal error: Can't open and lock privilege tables: Incorrect information in file: './mysql/proxies_priv.frm'
140812 15:23:11 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

以下のログに注目、proxies_priv.frmというファイルがぶっこわれているため怒っている様子。

140812 15:23:11 [ERROR] /usr/libexec/mysqld: Incorrect information in file: './mysql/proxies_priv.frm' 

/var/lib/mysql/mysql/proxies_priv.frmをリネームする

mv proxies_priv.frm proxies_priv.frm_tes

そして再度mysql startを実行、三度目の正直だ・・。

/etc/rc.d/init.d/mysqld start
Starting mysqld:                                           [  OK  ]

やった、やっと起動した!



・・・・宣伝です・・・・
Twitterアカウント同士でバトルするRPGツイッターバトラーズ!」というゲーム作りました!
よかったら遊んでみてね。
f:id:absg:20150531173308j:plain:w200