Skip to main content

GET ALL WORDPRESS THEMES - ONLY €59.00 (15 WordPress Pixelemu themes) Read more

WordPress Tutorials

Error establishing a database connection in WordPress.

You have been seen probably this error: Error Establishing a Database Connection in Wordpress. This error can be caused by many reasons. That's very frustrating, especially if it happens to you. We want to show a list of possible causes for this problem.

NOTE: Please remember to backup before any action.

Does the problem is visible also for WP dashboard?

 Please check if WP dashboard shows other error than Error Establishing a Database Connection. Then you probably need to repair the database. Fortunately, WordPress has his tool for it. To use it, add this line to wp-config.php file.

define('WP_ALLOW_REPAIR', true);

Now go to URL:

You will see the similar screen:

Error establishing a database connection in Wordpress

Now you can repair or repair & optimize the database. Please remember to remove your changes in wp-config.php file when you are done.

Database credentials in wp-config.php

Now we are checking if database credentials are correct in wp-config.php file. There you have these lines:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'localhost');

Please check if all of these fields (user, password, database, host) are right, especially if you have changed user's password recently.

Sometimes the problem is related to the hostname. On most hosting servers we can use localhost as DB_HOST, but sometimes we should use IP address, hosting's particular name or hosting's address. For example in hosting GoDaddy we use:

define('DB_HOST', '');

Second example - 1and1:

define('DB_HOST', 'db12345678');


Still not working? Order our service

Database user privileges

You can create this PHP script in file test_user.php:

<?php $pe_access= mysql_connect('localhost', 'database_username', 'database_password');
if (!pe_access) {
die('Could not connect: ' . mysql_error());
echo 'Connection is OK';
mysql_close(pe_access); ?>

Please remember to change database_username and database_password to match your credentials. Now copy this file to your WP root and enter it by URL:

If you get the message, Connection is OK your user has correct privileges. If you get the other message there could be something wrong with it.

New user and password for database

You can access your cPanel and try to create new database's user and add this new user to the database used in your WP site. Please give him all privileges. Now edit wp-config.php file and change lines:

define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');


Site URL in database

On more thing that you can try is attempt to override Site URL in the database.

Go to phpMyAdmin (of course if you can) and run SQL command:

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

Please remember to change to your website URL. Check also if you have the standard wp_ prefix in database tables. If your prefix is, for example, my_ your command will look like:

UPDATE my_options SET option_value='' WHERE option_name='siteurl'


Server overload

If you have checked above solutions and none of them worked out, we can cavil our server. If you have on the same server other websites, please try to visit them. If they'are not alive that definitely server's cause.

You can also enter phpMyAdmin and check if you can access your database using username and password used in wp-config.php file. If you can't access database there the most probably reason is that MySQL server is down.

If none of the solutions are working for You, contact your hosting and ask them is MySQL server is working correctly.

Still not working? Order our service

Satisfaction guaranteed

Connect With Us


ul. Przyjaźni 9, 84-215 Gowino, registered in Centralna Ewidencja i Informacja o Działalnosci Gospodarczej
NIP/VATID: PL5882424318

Copyright © 2009-2021 All rights reserved.