本地主机中的 Wordpress 多站点“建立数据库连接时出错”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19724781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress Multisite "Error establishing a database connection" in localhost
提问by user1987095
When attempting to convert WordPress to a Multisite setup, I get the error:
尝试将 WordPress 转换为多站点设置时,出现错误:
Error establishing a database connection
建立数据库连接时出错
I'm using WordPress 3.7.1 on Windows 7 with a WAMP server.
我在带有 WAMP 服务器的 Windows 7 上使用 WordPress 3.7.1。
wp-config.php
wp-config.php
define('WP_ALLOW_MULTISITE', true );
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/wordpress_test4/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
.htaccess
.htaccess
RewriteEngine On
RewriteBase /wordpress_test4/
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ [L]
RewriteRule . index.php [L]
回答by Dima L.
You need to add to your wp-config.php
:
您需要添加到您的wp-config.php
:
define('MULTISITE', true);
I had the same problem. I skipped this line because I already had define('WP_ALLOW_MULTISITE', true);
in my wp-config and it looked to me the same.
我有同样的问题。我跳过了这一行,因为define('WP_ALLOW_MULTISITE', true);
我的 wp-config 中已经有了它,它在我看来也是一样的。
回答by Sabin Chirila
Had same problem, found 3 possible solutions:
有同样的问题,找到了 3 种可能的解决方案:
Make sure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in your wp-config.php are really the ones expectected.
As Dima L. mentioned before, define('MULTISITE', true);is expected too.
(what solved it for me) Setting up multi-site for wordpress, changed the 'wp_blogs' table's column 'path' to an undefined location for my website. I changed it to "/" and the DB connection was re-established.
确保: wp-config.php 中的 DB_NAME、DB_USER、DB_PASSWORD 和 DB_HOST 确实是预期的。
正如 Dima L. 之前提到的,define('MULTISITE', true); 也很期待。
(为我解决了什么问题)为 wordpress 设置多站点,将 'wp_blogs' 表的列 'path' 更改为我网站的未定义位置。我将其更改为“/”并重新建立了数据库连接。
回答by Sorin Haidau
I struggled a long time because of this issue. And finally found a solution.
因为这个问题,我挣扎了很长时间。并最终找到了解决方案。
You should not add all those settings at once in the wp-config.php file. Follow the exact steps described here: http://codex.wordpress.org/Create_A_Network
您不应该在 wp-config.php 文件中一次添加所有这些设置。按照此处描述的确切步骤进行操作:http: //codex.wordpress.org/Create_A_Network
Only add the following code as the first step:
只需添加以下代码作为第一步:
/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
And then refresh your page. After that, in your administration panel go to Tools -> Network Setupand choose your sub-site settings.
然后刷新您的页面。之后,在您的管理面板中转到工具 -> 网络设置并选择您的子站点设置。
For the rest, just use the instructions from the link above.
其余的,只需使用上面链接中的说明。
Good luck!
祝你好运!
回答by Torsten McFly
I had a strange encounter very recently. After setting up a dev server which runs under a different domain and moving a multisite setup to it I got the same error “Error establishing a database connection”. I had checked that all the wp_options tables have the correct domains in the respective settings and that my database connection had the right credentials and would work under normal circumferences.
我最近有一次奇怪的遭遇。设置在不同域下运行的开发服务器并将多站点设置移至该服务器后,我收到相同的错误“建立数据库连接时出错”。我已经检查过所有 wp_options 表在各自的设置中都具有正确的域,并且我的数据库连接具有正确的凭据并且可以在正常范围内工作。
I found a way to get a better error reporting. I added an output of the database object in the function dead_db() in functions.php which then showed me that it couldn't find any blogs for my site in the table wp_blogs. I simply forgot to update the domains for the test server in this table.
我找到了一种获得更好的错误报告的方法。我在functions.php 的dead_db() 函数中添加了一个数据库对象的输出,然后它告诉我它在wp_blogs 表中找不到我网站的任何博客。我只是忘记更新此表中测试服务器的域。
function dead_db() {
global $wpdb;
echo "<pre>";
print_r($wpdb);
echo "</pre>";
wp_load_translations_early();
Hope that helps someone :)
希望对某人有所帮助:)
回答by Irandoust
My DOMAIN_CURRENT_SITEin wp-config.php was define('DOMAIN_CURRENT_SITE', 'www.example.com');
Removing "http://" in wp_blogs -> domain fixed my issue.
我的DOMAIN_CURRENT_SITE在WP-config.php中是定义( 'DOMAIN_CURRENT_SITE', 'www.example.com');
删除wp_blogs -> 域中的“ http://”修复了我的问题。
回答by D.A.H
I added $base = '/';into config, which solved issue.
我添加了$base = '/'; 进入配置,解决了问题。
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'mydomain.com');
$base = '/';
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
回答by para
I had the problem after moving the multisite from a sub directory to the root directory.
将多站点从子目录移动到根目录后,我遇到了问题。
What solved it for me was partly what has been mentioned by Sabin Chirila :
为我解决的部分是 Sabin Chirila 提到的:
- Make sure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in your wp-config.php are really the ones expectected.
- As Dima L. mentioned before, define('MULTISITE', true); is expected too.
- Change the 'wp_blogs' table's column 'path' to "/" and the DB connection was re-established.
- 确保: wp-config.php 中的 DB_NAME、DB_USER、DB_PASSWORD 和 DB_HOST 确实是预期的。
- 正如 Dima L. 之前提到的,define('MULTISITE', true); 也很期待。
- 将 'wp_blogs' 表的 'path' 列更改为“/”并重新建立数据库连接。
but I had to change some more things.
但我不得不改变一些更多的东西。
- In order to be able to view the frontend I also had to change the 'wp_site' table's column 'path' to "/"
- and then (in theme twentyseventeen-child) I had to reconfigure some configuration settings in the backend as they weren't taken into account. But that was simple as the data was still there.
- 为了能够查看前端,我还必须将“wp_site”表的“路径”列更改为“/”
- 然后(在主题二十七孩子)我不得不在后端重新配置一些配置设置,因为它们没有被考虑在内。但这很简单,因为数据仍然存在。
回答by Oliver Tappin
If you're running WHM/cPanel and you've already checked that you've added the MULTISITE
/WP_ALLOW_MULTISITE
constant, you're probably running into virtual host issues.
如果您正在运行 WHM/cPanel 并且您已经检查过是否添加了MULTISITE
/WP_ALLOW_MULTISITE
常量,那么您可能会遇到虚拟主机问题。
If you're getting the database error, chances are, your name servers or A record is correct. Otherwise your domain wouldn't be pointing to your server with a database connection. But, you've probably forgotten, or missed, the domain name from the cPanel aliases.
如果您收到数据库错误,很可能是您的名称服务器或 A 记录是正确的。否则您的域将不会通过数据库连接指向您的服务器。但是,您可能已经忘记或错过了cPanel aliases 中的域名。
Just head to cPanel, search for 'Aliases' and type in the domain name you're missing under 'Create a New Alias'.
只需前往 cPanel,搜索“别名”并在“创建新别名”下输入您缺少的域名。
You can also get to cPanel by logging into WHM, searching for 'List Accounts', searching for the account you want and clicking on the CP icon.
您还可以通过登录 WHM、搜索“列出帐户”、搜索您想要的帐户并单击 CP 图标来访问 cPanel。
回答by azvonko
Besides to all said above, if working with multisite environment please check also the following: in the respective subdirectories (/home/subsitename) there exist separate wp-config.php and .htaccess files for each of (sub)sites, so the above mentioned parameters have to be adjusted in all of these files. For example, my main site was working correctly since these files in my /home directory were OK, but when tried to access my sub-sites, I've been receiving database connection error message until I adjusted these files too.
除了上述所有内容,如果使用多站点环境,请检查以下内容:在相应的子目录 (/home/subsitename) 中,每个(子)站点都存在单独的 wp-config.php 和 .htaccess 文件,因此上述必须在所有这些文件中调整提到的参数。例如,我的主站点运行正常,因为 /home 目录中的这些文件正常,但是当我尝试访问我的子站点时,我一直收到数据库连接错误消息,直到我也调整了这些文件。
回答by JorgeLuisBorges
Here's How I fixed it
这是我修复它的方法
config settings
配置设置
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', 'localhost' );
define( 'PATH_CURRENT_SITE', '/myblog/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
then in the database table (found using phpmyadmin) wp_blogs set the values for your root blog (which should be lie/number 1) to
然后在数据库表中(使用 phpmyadmin 找到)wp_blogs 将根博客的值(应该是谎言/数字 1)设置为
domain localhost
root /myblog/
And finally - reset the sitrurl and homepage in options table (again found using phpmyadmin) to
最后 - 将选项表中的 sitrurl 和主页(再次使用 phpmyadmin 找到)重置为
http://localhost/myblog/