Contact Support : +64 220 256 070


Error establishing connection to database

Posted on: August 15, 2015

The database connectivity errors are common on database driven websites. The error appears when the script is unable to establish a database connection.


How to check the root cause of the issue.

1) It could be that your database login credentials are wrong or have been changed.

1 define('DB_NAME', 'database-name');
2 define('DB_USER', 'database-username');
3 define('DB_PASSWORD', 'database-password');
4 define('DB_HOST', 'localhost');

Check the WP configuration file wp-config.php and verify the login details are correct

2) Database may went unresponsive.

Make sure the database is running fine, if needed do restart.

3) Add the line define('WP_ALLOW_REPAIR', true); to the wp-config.php file.

It repairs the database.

4) Test the mysql connectivity using a simple script.
$link = mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
echo ‘Connected successfully’;

Test the script is working or not by loading it from the server.

5) Using the PHPMyadmin too update yopur siteurl.

Run the following query.

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'



Search Blog