WordPress Multisite – Error Establishing a Database Connection

Category: WordPressTags:

When you are moving a WordPress multisite website to a different url, you may get the error “Error establishing a database connection”. Based on the error description, you will likely try to verify database connection, username and password but still you are facing the error. In fact, this error is not related to database connection issue. It is related to the url stored in your database and wp-config.php file.

Moving Multisite to localhost

I wanted to create a test environment using my current PROD site. My PROD site uses WordPress Multisite with a subdirectory (and not subdomain). Once I imported database, changed wp-config.php, created web application in IIS server and tried to access site, it gave me the above error.

I have verified database connection information multiple times thinking that there is something wrong with credentials or collation.

Error Caused by Settings And Not Database

After couple of trial and error, I figured out that this error is not caused by database connection issue but rather values stored in database and wp-config.php file.

Settings to Change

Here is what I did in order to make the site run on http://localhost/mytestsite. I needed to change wp_blogs, wp_options and wp_site tables. If your WordPress uses a table prefix other than wp, make sure you modify the correct MySQL tables.

Table: wp_blogs

This table contains list of all the blogs available on your multisite.

Change domain = ‘localhost’ and path = ‘/mytestsite/’ for the blog_id=1. Path must contains “/” at the beginning and at the end.

Table: wp_options

This table contains WordPress options. Change “siteurl” and “home” options’ option_value to “http://localhost/mytestsite/”. This must contain “/” at the end.

Table: wp_site

Change domain = ‘localhost’ and path = ‘/mytestsite/’ for the blog_id=1. Path must contains “/” at the beginning and at the end.

File: wp-config.php

Make sure that you have following constants defined.

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/mytestsite/'); // must contain "/" at the beginning and at the end
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Once I made above mentioned changes, site worked without any issue.



Your email address will not be published.

  1. Pdropi says:

    Solved with one line in wp-config.php :


  2. Rebeca M says:

    Thank you! The solution solved my problem

  3. The Elvis says:

    Thank you Vishal, you saved my day 🙂

  4. iancito says:

    Thanks Viyal, was loosing my mind to this.

  5. imran says:

    good work