一次重启mysql发现无法启动成功,通过检查mysql日志发现问题并解决了问题。 mysql启动失败的日志:
[root@nn ~]# tail -n 20 /var/log/mysqld.log130924 10:14:54 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist130924 10:14:54 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended130924 10:27:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist130924 10:27:09 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.130924 10:27:09 InnoDB: Initializing buffer pool, size = 8.0M130924 10:27:09 InnoDB: Completed initialization of buffer poolInnoDB: Log scan progressed past the checkpoint lsn 0 37356130924 10:27:09 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 doublewriteInnoDB: buffer...InnoDB: Doing recovery: scanned up to log sequence number 0 44233130924 10:27:09 InnoDB: Starting an apply batch of log records to the database...InnoDB: Progress in percents: 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 99InnoDB: Apply batch completed130924 10:27:10 InnoDB: Started; log sequence number 0 44233130924 10:27:10 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist130924 10:27:10 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
解决方法:运行mysql_install_db --user=mysql --ldata=/var/lib/mysql/,运行结果如下,问题解决:
[root@nn ~]# mysql_install_db --user=mysql --ldata=/var/lib/mysql/Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h hostbus.net password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script![root@nn ~]#[root@nn ~]# service mysqld startStarting mysqld: [ OK ]