Home » Wordpress » Error establishing a database connection (WordPress)

Error establishing a database connection (WordPress)

WordPress is the most popular content management system by far ahead its competitors. 32% of the all websites are powered by this amazingly easy to install blogging system. Even though the 5-minute installation is legendary, there is one error message that might give you a hard time during setup: “Error establishing a database connection”.

It sounds easy to fix but this error message may consume more time than you expect especially if you are using a hosting provider.

Here is the full error message and the screenshot:

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

Error establishing a database connection

If you go to installation page directly (e.g. address.com/blog/wp-admin/install.php) instead of the homepage (e.g. address.com/blog), you may see the error message below:

Server Error

500 – Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

Error establishing a database connection

In some cases, this is all we get:

Would you like to create WordPress posts from your .NET application? Check this post out: How to send a post to your WordPress blog in C# and ASP.NET

How to fix “Error establishing a database connection” error?

From the most common causes to the least ones, here are a few things to do.

Connection information

Make sure the database name, database username, password, and database address are correct. Double check this information. Instead of typing them, copy them directly from the hosting provider’s website to the wp-config-sample.php or the WordPress installation wizard.

Make sure the database you created is a MySQL database. In the administration consoles of some hosting providers, it’s easy to create an MSSQL database instead of MySQL database.

Database address is generally localhost. However, it could be an IP address or IP address + port number. For example: 151.563.53.62:334. If you are in doubt about the database address, ask your hosting provider or search in their support page.

Authentication keys

Even the experienced developers may forget about setting unique authentication keys. In the wp-config-sample.php file, there is a section for these phrases:

define(‘AUTH_KEY’, ‘put your unique phrase here’);
define(‘SECURE_AUTH_KEY’, ‘put your unique phrase here’);
define(‘LOGGED_IN_KEY’, ‘put your unique phrase here’);
define(‘NONCE_KEY’, ‘put your unique phrase here’);
define(‘AUTH_SALT’, ‘put your unique phrase here’);
define(‘SECURE_AUTH_SALT’, ‘put your unique phrase here’);
define(‘LOGGED_IN_SALT’, ‘put your unique phrase here’);
define(‘NONCE_SALT’, ‘put your unique phrase here’);

Go to this address to automatically create all the unique phrases you need. You can simply copy and paste the generated text.

Is Google Search Console showing “Error in required structured data element” error for your WordPress blog? Check this post out: Error in required structured data element” (AMP issue)

Limits and support

It rarely happens but sometimes users try to install WordPress in a hosting that doesn’t support PHP. Make sure that your hosting account has PHP support. Additionally, check if you have reached to database and user creation limit.

Had a different issue? Drop a comment please!

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

2 thoughts on “Error establishing a database connection (WordPress)”

Leave a Comment