WordPress Multisite – Error Establishing a Database Connection

Category: WordPressTags:

If you get the error “Error establishing a database connection” when you are moving a WordPress multisite website to a different url, this error is not related to database connection. 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 the 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

Table: prefix_blogs

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

Table: prefix_options

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

Table: prefix_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

I 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. Required fields are marked *

  1. iancito says:

    Thanks Viyal, was loosing my mind to this.

  2. imran says:

    good work