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]
ShareFollow
9,1761212 gold badges4343 silver badges4646 bronze badges
asked Nov 1, 2013 at 10:18
42922 gold badges88 silver badges1818 bronze badges
- please update your post to separate the htaccess and wp-config for readability. – phil Nov 1, 2013 at 10:21
- 3To begin with: 1. Check your DB server is running and 2. Check your username/password/database name/hostname are correct – phil Nov 1, 2013 at 10:21
- It is all in my local-host,meaning desktop – user1987095 Nov 1, 2013 at 10:24
- Is your local DB server running? Do you have the correct username/password/db name/hostname? – phil Nov 1, 2013 at 10:49
- When i remove the multisite portion and change htaccess ,it is working – user1987095 Nov 1, 2013 at 10:55
12 Answers
Sorted by: Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
68
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.
ShareFollow
answered Jan 26, 2014 at 20:33
3,2333131 silver badges2929 bronze badges
- 11same here.. I was over smart 🙂 fixed now – Wasim Shaikh Dec 10, 2015 at 14:11
- 3Whaddehel.. I have the exact same problem. Twice! Thanks mate. This solved my .. silly issue 🙂 fixed too – swdev Jul 14, 2017 at 13:52
- Worked for met too. I had to scroll down to the end of the page. This should be marked as the right answer 🙂 – jmontenegro Aug 16, 2017 at 18:25
- And me. Thanks for the heads up. – Dan382 Oct 22, 2018 at 19:59
- And me. Thanks. You saved me hours! – flymike May 20, 2020 at 15:24
43
Had same problem, found 3 possible solutions:
- Make sure:
DB_NAME
,DB_USER
,DB_PASSWORD
, andDB_HOST
in your wp-config.php are really the ones expectected. - As Dima L. mentioned before,
define('MULTISITE', true);
is expected too. - But what solved it for me* is etting up multi-site for WordPress, changed the
wp_blogs
table’s columnpath
to an undefined location for my website. I changed it to/
and the DB connection was re-established.
ShareFollow
25.2k1111 gold badges6969 silver badges9797 bronze badges
answered Feb 22, 2014 at 20:03
71966 silver badges88 bronze badges
- 2Your Solution helped me! 2 years old ans still a very usefull comment. Thank you! – Kendel Ventonda Dec 13, 2016 at 1:10
- 2Thank you, your comment pointed me to look into the blogs table and correct the root domain that was on dev url still. The default error is horribly generic and I spent days proving the new SQL server was installed and accessible before I realised it was a multisite I had been given and adding that to the search led me here. – Elijha Jan 24, 2019 at 4:12
- 2Thanks. Point 3 helped me +1. – w0051977 Sep 4, 2020 at 9:21
- Thanks a lot. saved me 😀 number 3 is the work for me. – Sudesh Lakmal Pathirana Apr 27, 2021 at 7:59
- Search is helpful:
wp search-replace 'old.com' 'new.com' --all-tables --precise --dry-run
– WhereDidMyBrainGo Sep 27, 2021 at 0:40
17
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
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 Setup and choose your sub-site settings.
For the rest, just use the instructions from the link above.
Good luck!
ShareFollow
answered Jun 3, 2016 at 21:45
72088 silver badges1717 bronze badges
- 2Missed adding define(‘MULTISITE’, true); which gave me a Database Error. Check you follow the steps in order. – Jason May 15, 2017 at 18:26
7
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.
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.
function dead_db() {
global $wpdb;
echo "<pre>";
print_r($wpdb);
echo "</pre>";
wp_load_translations_early();
Hope that helps someone 🙂
ShareFollow
answered Aug 25, 2016 at 0:59
7111 silver badge22 bronze badges
- strangely, i did
print_r($wpdb)
and it started working – DC- Sep 19, 2021 at 17:20 - The fact that a proper version of this hasn’t been added to output to logs or at least debug wordpress issues is just mind boggling – rantsh Mar 3 at 20:22
4
My DOMAIN_CURRENT_SITE
in wp-config.php
was define('DOMAIN_CURRENT_SITE', 'www.example.com');
Removing http://
in wp_blogs -> domain fixed my issue.
ShareFollow
25.2k1111 gold badges6969 silver badges9797 bronze badges
answered May 14, 2016 at 20:48
53255 silver badges1212 bronze badges
3
I added $base = ‘/’; into the config, which solved the 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);
ShareFollow
9,213146146 gold badges8585 silver badges118118 bronze badges
answered Dec 25, 2014 at 7:49
83422 gold badges99 silver badges1818 bronze badges
- 1Do you happen to know WHY this works? I cannot easily find any information about the $base variable. And THANK YOU. My issue seemed different than some other people’s here, and of all the other solutions here, this is the one that fixed the problems for me. I had proved that by commenting out all of the multisite configuration variables, the MAIN website worked but it thought it was a standalone install. With multisite enabled, all requests got the “Error Establishing Database Connection” error. Adding this one variable here fixed all my subsites! – Dave McHale Mar 10, 2021 at 16:20
3
If you have taken an entire database dump of a multisite, you would have to change the domain name to match your localhost domain on the following tables:
- wp_blogs [update the domain fields]
- wp_options [siteurl and home]
- wp_site [domain field]
For a multisite, defining WP_HOME and WP_SITEURL on the config.php will not work.
Ideally before importing the DB dump, if you have the .sql file, you could do a search and replace of all the domains to your own localhost domain.
These above steps worked for me.
ShareFollow
answered Jul 15, 2021 at 18:33
1731212 bronze badges
1
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.
ShareFollow
answered Nov 8, 2014 at 11:54
1122 bronze badges
1
Inspired by Sabin’s answer, I checked wp_blogs
and found that the domain
value was still pointing to the wrong domain (I was moving a multi-site to a dev server). Running UPDATE wp_blogs SET domain='example.com';
fixed my issue (note that I’m using subfolder multisite, not subdomain – don’t blindly run that SQL!)
ShareFollow
answered Aug 6, 2015 at 17:51
23155 silver badges1414 bronze badges
1
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.
ShareFollow
answered Nov 8, 2017 at 23:05
2,45111 gold badge2323 silver badges4242 bronze badges
1
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 :
- 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.
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.
ShareFollow
15k22 gold badges3535 silver badges5757 bronze badges
answered Aug 26, 2017 at 19:38
2122 bronze badges
- 1could you explain how you complete step 4, and change the ‘wp_site’ table’s column ‘path’ to “/” – fuzzi Aug 13, 2019 at 19:05
0
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
domain localhost
root /myblog/
And finally – reset the sitrurl and homepage in options table (again found using phpmyadmin) to
http://localhost/myblog/
ShareFollow
source : https://stackoverflow.com/questions/19724781/wordpress-multisite-error-establishing-a-database-connection-in-localhost