简体   繁体   English

无法将Wordpress连接到MySQL数据库

[英]Cannot connect Wordpress to MySQL database

Doing some local website work to learn Wordpress theme development. 做一些本地网站工作来学习Wordpress主题开发。

Tried to set up Wordpress through the prompts, also tried it by manually entering information in the wp-config.php file, neither would work. 试图通过提示设置Wordpress,也尝试通过手动输入wp-config.php文件中的信息,两者都不起作用。 Still cannot connect to the database, the setup-config.php page returns "Error establishing a database connection". 仍然无法连接到数据库,setup-config.php页面返回“建立数据库连接时出错”。 I've double, triple, and quadruple checked the login credentials (database name, username, password etc.), they are complete and correct. 我有双倍,三倍和四倍检查登录凭据(数据库名称,用户名,密码等),它们是完整和正确的。 Deleted wp-config.php and tried again through the web page, same result. 删除了wp-config.php并再次尝试通过网页,结果相同。

MySQL is definitely running, the Mac System Preferences panel says so, and I can login and run SQL queries at the command line, although I have to do that as root. MySQL肯定在运行,Mac System Preferences面板就是这样说的,我可以在命令行登录并运行SQL查询,尽管我必须以root身份执行。 Should I be running MySQL as root? 我应该以root身份运行MySQL吗?

This problem exists with Wordpress and also with an instance of phpMyAdmin that I've also installed, so I don't think it's anything to do with the PHP code as such, it smells more like a permissions thing. 这个问题与Wordpress以及我也安装的phpMyAdmin实例一起存在,所以我认为它与PHP代码没有任何关系,它更像是一个权限的东西。 For what it's worth, I've edited my httpd.conf file to get Wordpress on port 80 and phpMyAdmin on 8081. Apache is serving those sites up as it should and PHP is running, it's just getting either site to connect to the database that's the problem. 为了它的价值,我编辑了我的httpd.conf文件以获得端口80上的Wordpress和8081上的phpMyAdmin.Apache正在为这些网站服务并且PHP正在运行,它只是让任一站点连接到数据库问题。

System information: 系统信息:

Mac OS X 10.9.5 (Mavericks) Mac OS X 10.9.5(小牛队)

PHP Version 5.4.30 PHP版本5.4.30

MySQL version: mysql Ver 14.12 Distrib 5.0.45, for apple-darwin9.2.0 (i686) using EditLine wrapper MySQL版本:mysql Ver 14.12 Distrib 5.0.45,适用于使用EditLine包装器的apple-darwin9.2.0(i686)

在我的情况下,它就像更改DB_HOST一样简单,因此它在wp-config.php中使用了正确的主机和端口:

define('DB_HOST', '127.0.01:3306');

I found the solution on this stackoverflow page . 我在这个stackoverflow 页面上找到了解决方案。

By default, Apache cannot send requests to a remote MySQL server. 默认情况下,Apache无法向远程MySQL服务器发送请求。 It should be enabled. 它应该启用。

On CentOS 6 the solution is the command: 在CentOS 6上,解决方案是命令:

setsebool httpd_can_network_connect=1

Check your phpinfo(); 检查你的phpinfo(); to see if MySQL extension for php is installed. 看看是否安装了MySQL的MySQL扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM