
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!
More Posts related to PHP,
- How to destroy PHP session()
- PHP Code for sending Emails
- 403 forbidden error for Image
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- Upload Pdf file using PHP Script
- PHP header location function not called
- Copy file from one directory to other in Php
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes
- PHP Base64 encoding decoding a variable
- PHP Fatal error : Call to a member function bind_param() on a non-object
- PHP Script to Upload Images to Server
- Upload docx file using PHP script
- How to Pretty Print JSON in PHP
- PHP Warning: Cannot modify header information - headers already sent
- PHP drag and drop file upload tutorial using dropzone.js
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP 301 Redirect Permanently
- Call PHP function on Button click using jquery ajax
- Installing vue.js in Laravel 8
- Save current timestamp in MySQL using PHP mysqi binding
- Delete file using PHP code : unlink()
More Posts:
- Disable Chrome Notification bell from Mac OS X menu bar - Mac-OS-X
- connection.url property value in hibernate.cfg.xml for mysql - Java
- [fix] bash: gradlew: command not found - Gradle
- Create S3 bucket using AWS CLI Command mb - AWS
- Show/Hide Hidden Files and Directories on Mac Finder - MacOS
- Java Program: Random Number Generator - Java
- Enable Dark Mode in Google Search - Google
- Device not compatible error Android Google Play Store - Android