今天在Apache中开启SELinux后修改/var/www/下文件的安全上下文后,重启httpd服务,打开网页出现以下错误:
<code> Error establishing a database connection </code>
以为是没有启动mysql服务,重启mysql服务,出现错误:
<code> [root@www ~]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ Failed ] </code>
在本地启动mysql也出现错误:
<code> [root@www www]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) </code>
查看日志文件:
<code> [root@www ~]# tail /var/log/mysqld.log 150505 21:56:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql /usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist 150505 21:56:59 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 150505 21:56:59 InnoDB: Initializing buffer pool, size = 8.0M 150505 21:56:59 InnoDB: Completed initialization of buffer pool 150505 21:56:59 InnoDB: Started; log sequence number 0 44243 150505 21:56:59 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist 150505 21:56:59 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended </code>
使用如下命令便能解决此问题。
<code> [root@www ~]# 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 www.feiyu1.com 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@www ~]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] </code>
经搜索,这是初始化MySQL的一个命令,当MySQL的系统库(mysql系统库)发生故障或需要新加一个mysql实例时,需要初始化mysql数据库。