[ wordpress ] “Error establishing database connection” after migration

When we migrate the wordpress from one host to the others, one common error we got is “Error establishing database connection”.

The solution is

  • update ‘wp_options’ table by setting ‘siteurl’ row to the new URL. i.e.  ‘http://localhost/blog’.
  • update ‘wp_blogs’ table set the ‘domain’ column to the new URL. i.e. ‘localhost’

That’s it.

PS.

– The Preview theme does not show up :

The ‘wp_options’ table may have to be updated by setting ‘home’ row to the new URL, i.e.  ‘http://localhost/blog’. In order for the ‘get_option(‘home’)’ in ‘wp-includes/functions.php’ to get the right value.

– The rest of the path is at

  • wp-config.php
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/blog');
  • ‘wp_site’ table, ‘wp_sitemeta’ table
  • home row in ‘wp_options’ shows the home URL of all the link in the web