Error establishing a database connection
This either means that the username and password information in your
wp-config.php file is incorrect or that contact with the database server at localhost could not be established.
This could mean your hostβs database server is down.
Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?
If you are unsure what these terms mean you should probably contact your host.
If you still need help you can always visit the WordPress Support Forums.
Step 1: Open wp-config.php and check WordPress credentials.
The first thing that you will do is open the wp-config.php on your hosting server (GoDaddy, Hostinger, Azure, AWS, etc) and make sure that the following details are correct.
/** The name of the database for WordPress */
define('DB_NAME', "prod-user' );
/** Database username */
define('DB_USER', 'myuser' );
/** Database password */
define('DB_PASSWORD', 'Password123');
/** Database hostname */
define( 'DB_HOST', 'localhost' );
- DB_NAME: The name of your database (could be MySQL, Windows SQL Server, AWS Aroura, etc.)
- DB_USER: The user name to access the database.
- DB_PASSWORD: The database password.
- DB_HOST: Usually the value is localhost or 127.0.0.1, or can be an AWS like "arn:aws:rds:region:account-id:db:db-instance-name" or Azure Connection String for SQL Database like - "26f-dbserver.mysql.database.azure.com"
Step 2: Check the Database Server is running
Make sure that the database server is up and running and you are able to connect it from the application server via telnet or ping if possible.
Example:telnet prod-db 3306
Step 4: Try to Test Database Connection Programatically
The quickest way to troubleshoot this error is by creating a simple test.php file under the WordPress root folder and see what's wrong.
Example:<?php
$db_link = mysqli_connect('localhost', 'your_db_username', 'your_db_password');
if (!$db_link) {
die('Could not connect to database: ' . mysqli_error());
}
echo 'Connected to the database was successful;
mysqli_close($db_link);
?>
Access this page via url http://<your-domain-name>/test.php
Step 5: Contact your Hosting/Cloud Support
If nothing worked, better get in touch with your Hosting (say GoDaddy, Hostinger) or your Cloud Service Provider (say Amazon AWS, Microsoft Azure or Google Cloud Storage)
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Delete file using PHP code : unlink()
- PHP header location function not called
- 403 forbidden error for Image
- Call PHP function on Button click using jquery ajax
- How to Pretty Print JSON in PHP
- Step-by-Step Guide: How to Fix - Error Establishing a Database Connection in WordPress
- PHP Base64 encoding decoding a variable
- PHP Fatal error : Call to a member function bind_param() on a non-object
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes
- PHP drag and drop file upload tutorial using dropzone.js
- Upload Pdf file using PHP Script
- PHP Warning: Cannot modify header information - headers already sent
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- PHP Code for sending Emails
- How to destroy PHP session()
- Installing vue.js in Laravel 8
- PHP 301 Redirect Permanently
- Upload docx file using PHP script
- Save current timestamp in MySQL using PHP mysqi binding
- Copy file from one directory to other in Php
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP Script to Upload Images to Server
- Android Toast position top - Android
- Windows 11 Notepad Find and Replace All Text Example - Windows-11
- How to switch Eclipse IDE Workspace - Eclipse
- How to come out of dquote prompt in Terminal - macOS/Linux - MacOS
- How to open TextEdit from Mac Terminal - MacOS
- Get Desc of Table using Java JDBC - Java
- How to install Google Chrome on macOS using Terminal Command - Chrome
- How to Generate SHA-256 Hash in Java With Example - Java