wordpress出现Error establishing a database connection

wordpress出现Error establishing a database connection


DATE: 2017-09-24 19:27:33

这个问题的原因是网站调用数据库的配置文件没有配置正确,无法正常调用 Mysql。

解决方法是配置wordpress目录下的wp-config.php文件。

需要修改的有以下几个参数:

参数说明示例
database_name_here数据库名wordpress
username_here数据库的用户名root
password_here数据库的密码wordpress@passwd



代码内容如下:

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

还需要检查wordpress.conf中指定的root路径是否正确。
具体参见关于wordpress.conf相关的配置说明

一切OK后,登录时需要先登录wp-admin/install.php,安装配置wordpress。如下图所示:
wordpress正常登录

可惜,还是有报错。

Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

 - Are you sure you have the correct username and password?
 - Are you sure that you have typed the correct hostname?
 - Are you sure that the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

原因是mysql用户名没有正确创建。

/usr/bin/mysqladmin -u root password 'MyPas$word4Word_Press'
chkconfig mysqld on

进入mysql环境,创建wordpress数据库并退出。

[root@VM_42_160_centos blog]# mysql -uroot -p
Enter password: 
... <中间输出省略> ...
mysql> 
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye

配置完成后,正常的安装界面如下:
这里写图片描述

安装完成后,登录即可开始使用。快体验搭建好的Blog吧!

版权声明

弈心博客


本文首发site_name,转载请附上博文链接!