mysql提示Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist解决方法

时间:2022-09-20 08:40:07

一次重启mysql发现无法启动成功,通过检查mysql日志发现问题并解决了问题。 mysql启动失败的日志:

[root@nn ~]# tail -n 20 /var/log/mysqld.log
130924 10:14:54 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
130924 10:14:54 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
130924 10:27:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
130924 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.0M
130924 10:27:09  InnoDB: Completed initialization of buffer pool
InnoDB: Log scan progressed past the checkpoint lsn 0 37356
130924 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 doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 44233
130924 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 99
InnoDB: Apply batch completed
130924 10:27:10  InnoDB: Started; log sequence number 0 44233
130924 10:27:10 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
130924 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...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE 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_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly 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.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[root@nn ~]#
[root@nn ~]# service mysqld start
Starting mysqld:                                           [  OK  ]