Wordpress Multisite “Error establishing a database

2019-03-12 19:09发布

When attempting to convert WordPress to a Multisite setup, I get the error:

Error establishing a database connection

I'm using WordPress 3.7.1 on Windows 7 with a WAMP server.

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

RewriteEngine On 
RewriteBase /wordpress_test4/ 
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin 
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^ - [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] 
RewriteRule . index.php [L]

标签: wordpress
11条回答
劫难
2楼-- · 2019-03-12 19:20

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.

查看更多
霸刀☆藐视天下
3楼-- · 2019-03-12 19:21

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.

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.

Just head to cPanel, search for 'Aliases' and type in the domain name you're missing under 'Create a New Alias'.

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-03-12 19:25

I added $base = '/'; into config, which solved issue.

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);
查看更多
祖国的老花朵
5楼-- · 2019-03-12 19:26

I had the problem after moving the multisite from a sub directory to the root directory. Wat solved it for me was partly what has been mentioned by Sabin Chirila : 1. Make sure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in your wp-config.php are really the ones expectected. 2. As Dima L. mentioned before, define('MULTISITE', true); is expected too. 3. Change the 'wp_blogs' table's column 'path' to "/" and the DB connection was re-established.

but I had to change some more things.

  1. In order to be able to view the frontend I also had to change the 'wp_site’ table's column 'path' to "/"
  2. 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.
查看更多
男人必须洒脱
6楼-- · 2019-03-12 19:29

Had same problem, found 3 possible solutions:

  1. Make sure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in your wp-config.php are really the ones expectected.

  2. As Dima L. mentioned before, define('MULTISITE', true); is expected too.

  3. (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.

查看更多
趁早两清
7楼-- · 2019-03-12 19:30

You need to add to your 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.

查看更多
登录 后发表回答