Fixing the 'Error Establishing a Database Connection' During WordPress Installation
Content
Encountering the "Error establishing a database connection" message while trying to install WordPress is a common and frustrating experience. This guide will walk you through the most frequent causes and their solutions, based on community troubleshooting.
Why This Error Occurs
This error is WordPress's way of saying it cannot communicate with your MySQL or MariaDB database. The installation cannot proceed without this vital connection. The problem is almost always related to incorrect configuration, a missing component, or the database server itself not being ready.
Step-by-Step Troubleshooting Guide
1. Verify Your Database Server is Running
Before troubleshooting anything else, confirm your database server is online. In tools like XAMPP, WAMP, or MAMP, there is typically a control panel where you can visually confirm that the MySQL or MariaDB service has a "Running" status. On a Linux server, you might use a command like sudo systemctl status mysql.
2. Confirm the Database Exists
WordPress cannot create a database; it can only populate an existing one with tables. You must manually create the empty database first using a tool like phpMyAdmin or a command-line interface. Double-check that the database name in your wp-config.php file matches the name you created exactly, including case sensitivity on some systems.
3. Check User Permissions
Creating a database user is not enough. The user must also have been granted all privileges to the specific database you created. A user with access to one database cannot necessarily access another. Log into phpMyAdmin, go to the "User accounts" section, and edit the privileges for your WordPress user to ensure they have full access to the correct database.
4. Review Your wp-config.php Credentials
This is the most common source of problems. The credentials in your wp-config.php file must be perfect.
- Database Name: Must match the name of the database you created.
- Username & Password: Must match the database user's login credentials exactly.
- Database Host: For local installations, this is almost always
localhost. However, some local server stacks like MAMP may use a custom port (e.g.,localhost:8889orlocalhost:3307). If the standardlocalhostdoes not work, check your server stack's documentation for the correct MySQL port and specify it in the host field (e.g.,localhost:3307). - Special Note: Avoid using spaces in your database name or username, as this can require additional formatting and often leads to connection issues.
5. Ensure the Required PHP Extension is Installed
WordPress requires the mysqli PHP extension to communicate with MySQL/MariaDB databases. If you are on a custom server setup (like FreeBSD or a minimal Linux install), you may need to manually install this package (e.g., php74-mysqli or similar) and restart your web server.
6. Try a Manual wp-config.php Setup
If the web-based installer consistently fails, manually create your configuration file.
- Locate the
wp-config-sample.phpfile in your WordPress directory. - Open it in a text editor and fill in your database details (
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST). - Save the file as
wp-config.php(notwp-config-sample.php). - Now, run the WordPress installation by visiting your site URL. It should skip the database setup step and begin creating the admin account.
7. Rule Out Database Server Compatibility
WordPress is designed to work with MySQL or MariaDB. It will not work with Microsoft SQL Server. Furthermore, while it is generally compatible with cloud-managed MySQL services, you may need to adjust specific settings on those platforms, such as disabling SSL enforcement for the initial connection if required.
Need More Help?
If you've worked through all these steps and are still stuck, the best place to get help is the wider WordPress community. Be prepared to share the details of your setup (operating system, local server stack, etc.) and the specific steps you've already taken.
Related Support Threads Support
-
Error establishing database connection – how to proceed nowhttps://wordpress.org/support/topic/error-establishing-database-connection-how-to-proceed-now/
-
WordPress on IIShttps://wordpress.org/support/topic/wordpress-on-iis-6/
-
wp-config.php setup2 not respondinghttps://wordpress.org/support/topic/wp-config-php-setup2-not-responding/
-
Trying to install WordPress 5.6 on WAMPhttps://wordpress.org/support/topic/trying-to-install-wordpress-5-6-on-wamp/
-
Can’t install!https://wordpress.org/support/topic/cant-install-103/
-
Setting up WordPresshttps://wordpress.org/support/topic/setting-up-wordpress-3/
-
problem installing on laptophttps://wordpress.org/support/topic/problem-installing-on-laptop/
-
error install on local hosthttps://wordpress.org/support/topic/error-install-on-local-host/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-859/
-
Getting Error establishing a database connectionhttps://wordpress.org/support/topic/getting-error-establishing-a-database-connection-2/
-
fatal errorhttps://wordpress.org/support/topic/fatal-error-3248/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-1035/
-
Up loadining WordPress via XAMPPhttps://wordpress.org/support/topic/up-loadining-wordpress-via-xampp/
-
Error establishing a database connection on Linux localhosthttps://wordpress.org/support/topic/error-establishing-a-database-connection-on-linux-localhost/
-
Cannot Connect to Database Errorhttps://wordpress.org/support/topic/cannot-connect-to-database-error/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-987/
-
Cannot select databasehttps://wordpress.org/support/topic/cannot-select-database-6/
-
Installation problems with WordPresshttps://wordpress.org/support/topic/installation-problems-with-wordpress/
-
WP Installer doesn’t work with Mysql Sockethttps://wordpress.org/support/topic/wp-installer-doesnt-work-with-mysql-socket/
-
Connect my wordpress installation to a remote databasehttps://wordpress.org/support/topic/connect-my-wordpress-installation-to-a-remote-database/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-858/
-
SQL connection problems IIShttps://wordpress.org/support/topic/sql-connection-problems-iis/
-
Can’t see why database is not connecting no matter what I dohttps://wordpress.org/support/topic/cant-see-why-database-is-not-connecting-no-matter-what-i-do/
-
Error Establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-912/
-
Virtual host installation on Ubuntu 19.10https://wordpress.org/support/topic/virtual-host-installation-on-ubuntu-19-10/
-
Azure DB for MySql as a Database for setting up WordPress on Azure VMhttps://wordpress.org/support/topic/azure-db-for-mysql-as-a-database-for-setting-up-wordpress-on-azure-vm/
-
How Do I access ‘Repair WordPress Database’ facility on Localhost?https://wordpress.org/support/topic/how-do-i-access-repair-wordpress-database-facility-on-localhost/
-
WordPress on Raspberry Pihttps://wordpress.org/support/topic/wordpress-on-raspberry-pi/
-
Configuring WordPress with PostgreSQLhttps://wordpress.org/support/topic/configuring-wordpress-with-postgresql/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-1052/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-948/
-
Creating connection with databasehttps://wordpress.org/support/topic/creating-connection-with-database/
-
wordpress unable to use new MySQL Tablehttps://wordpress.org/support/topic/wordpress-unable-to-use-new-mysql-table/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-1033/
-
Can’t install and connect to Database in localhosthttps://wordpress.org/support/topic/cant-install-and-connect-to-database-in-localhost/
-
Cannot Install WordPress Xampp Error Establishing Connection with Databasehttps://wordpress.org/support/topic/cannot-install-wordpress-xampp-error-establishing-connection-with-database/
-
Error Establishing Database Connection (MAMP)https://wordpress.org/support/topic/error-establishing-database-connection-123/
-
Error establishig database connectionhttps://wordpress.org/support/topic/error-establishig-database-connection/
-
“error establishing database” “can’t select database” errorshttps://wordpress.org/support/topic/error-establishing-database-cant-select-database-errors/
-
Github peachpie-wordpress gives error connecting to databasehttps://wordpress.org/support/topic/github-peachpie-wordpress-gives-error-connecting-to-database/
-
cannot connect to serverhttps://wordpress.org/support/topic/cannot-connect-to-server/
-
There has been a critical error on this website installing wordpress locallyhttps://wordpress.org/support/topic/there-has-been-a-critical-error-on-this-website-installing-wordpress-locally/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-905/
-
Cannot connect to RDS MySQL DBhttps://wordpress.org/support/topic/cannot-connect-to-rds-mysql-db/
-
install.phphttps://wordpress.org/support/topic/install-php/
-
Error establishing a database connection, after saving wp-config.php file.https://wordpress.org/support/topic/error-establishing-a-database-connection-867/
-
Installing WordPress on XAMPPhttps://wordpress.org/support/topic/installing-wordpress-on-xampp/
-
Stuck when installing WP – “Error establishing a database connection”https://wordpress.org/support/topic/stuck-when-installing-wp-error-establishing-a-database-connection-2/
-
XAMPP database connection details problemhttps://wordpress.org/support/topic/xampp-database-connection-details-problem/
-
Error in Databasehttps://wordpress.org/support/topic/error-in-database-8/
-
Error Installing WordPress into XAMPPhttps://wordpress.org/support/topic/error-installing-wordpress-into-xampp/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-955/
-
Initial Database connection failinghttps://wordpress.org/support/topic/initial-database-connection-failing/
-
Can access database from shell, but not in sitehttps://wordpress.org/support/topic/can-access-database-from-shell-but-not-in-site/
-
Error establishing a database connection – Insecure authenticationhttps://wordpress.org/support/topic/error-establishing-a-database-connection-insecure-authentication/
-
Database Connections from Squarespacehttps://wordpress.org/support/topic/database-connections-from-squarespace/
-
DB_HOST not defined in WP-CONFIGhttps://wordpress.org/support/topic/db_host-not-defined-in-wp-config/
-
Call to undefined function mysql_connect() in /var/www/html/wp-includes/wp-db.phhttps://wordpress.org/support/topic/call-to-undefined-function-mysql_connect-in-var-www-html-wp-includes-wp-db-ph/
-
Trouble connecting to RDS DB from WordPress on EC2https://wordpress.org/support/topic/trouble-connecting-to-rds-db-from-wordpress-on-ec2/
-
error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-1103/
-
Creating connection with databasehttps://wordpress.org/support/topic/creating-connection-with-database-2/
-
database username and pwhttps://wordpress.org/support/topic/database-username-and-pw/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-1048/
-
Installazione manuale wordpress – problemi databasehttps://wordpress.org/support/topic/installazione-manuale-wordpress-problemi-database/
-
Errorhttps://wordpress.org/support/topic/error-1774/
-
new installation on Windows Serverhttps://wordpress.org/support/topic/new-installation-on-windows-server/
-
Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-979/
-
Error Establishing Database Connectionhttps://wordpress.org/support/topic/error-establishing-database-connection-146/