How I Fixed the “Error Establishing Database Connection” in XAMPP
If you’re seeing the dreaded “Error establishing a database connection” message while setting up WordPress on XAMPP, don’t panic. I faced the exact same problem recently and managed to fix it after some trial and error.
In this guide, I’ll walk you through the exact steps I followed to solve the error and successfully set up a local WordPress development environment on my PC.
Why I Needed XAMPP & WordPress Locally
It all started when I decided to learn how to build a simple WordPress plugin. One of the first recommendations I got (thanks, Claude AI!) was to set up a local WordPress development environment using XAMPP.
XAMPP lets you run Apache (the web server) and MySQL (the database) on your computer. There’s no need to buy hosting or a domain name.
Step 1: Installing XAMPP
I downloaded and installed XAMPP from the official website. The installation took a few minutes.
After that, I opened the XAMPP Control Panel and started both Apache and MySQL servers. Thankfully, this part was smooth.

Step 2: Creating a Database with phpMyAdmin
Next, I needed to create a database for WordPress. Here’s how:
- Opened Chrome and typed: localhost/phpmyadmin
- In phpMyAdmin, I created a new database called: wordpress_dev
At this stage, the database was empty, but that’s normal. WordPress will fill it with tables during installation.
Step 3: Installing WordPress Locally
I downloaded the latest version of WordPress and extracted the contents into this folder on my computer: c:\xampp\htdocs\wordpress
Then, I visited localhost/wordpress on my browser to begin the WordPress installation.
Step 4: The “Error Establishing Database Connection” Appears
During setup, WordPress asked for database details:
- Database Name
- Username
- Password
- Database Host
- Table Prefix
After entering the details, I immediately got:
Error establishing a database connection

Step 5: Troubleshooting the Error
I turned to Claude AI again for help. It explained that this error usually means WordPress cannot connect to the database, often due to incorrect information in the wp-config.php file.
Locating & Editing the WPConfig file
Inside the wordpress folder, I found a file called: wp-config-sample.php
I opened it and saw placeholder values like:
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
$table_prefix = 'wp_';
I updated these with my actual database details:
- Database Name: wordpress_dev
- Username: sufia (I chose this)
- Password: your_password_here
- Host: localhost
I also renamed the file to wp-config.php
Step 6: Enter a New Error: “Access Denied for User”
After updating the config file, I tried again in the browser but got a new message:
Access denied for user 'sufia'@'localhost' (using password: YES)
This meant the database didn’t recognize my chosen username (sufia) or the user didn’t have permission to access the database.

Step 7: Creating a New Database User (But Ran Into Another Error)
I figured I needed to create the sufia user in phpMyAdmin with the same password I used in wp-config.php.
However, when I tried to create the user, I encountered this error:
#3 - Error writing file 'C:\xampp\mysql\data\aria_log.00000001' (Errcode: 9 "Bad file descriptor") CREATE USER 'sufia'@'%' IDENTIFIED VIA mysql_native_password USING '***';GRANT ALL PRIVILEGES ON *.* TO 'sufia'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
Turns out, this happens due to a corrupted Aria log file in XAMPP’s MySQL data directory.

Step 8: The Solution That Finally Worked
Claude AI suggested deleting the problematic aria_log.00000001 file. Here’s exactly what I did:
- Navigated to C:\xampp\mysql\data
- Deleted the aria_log.00000001 file
- Restarted the MySQL server from the XAMPP Control Panel
After that, I was able to:
✅ Create a new user sufia with the correct password
✅ Grant all privileges to the user
✅ Go back to localhost/wordpress and enter the database details
This time, it worked!

I completed the WordPress setup and logged into my brand-new local WordPress site.

Thoughts on What I Learned
While this fix worked for me, keep in mind that:
- The “Error establishing a database connection” can happen for many reasons, such as incorrect credentials, corrupted files, MySQL not running, etc.
- Tools like Claude AI (or ChatGPT) are helpful for troubleshooting, but you may need to try multiple solutions.
It took me over an hour to figure this out, but it was worth it. I learned about how WordPress and databases work together.
Let me know if this article helped you solve the “error establishing database connection” error in XAMPP. If not, still leave a comment detailing the problems you are encountering. I’ll try to help find a solution.