[Fixed] XAMPP Error Establishing Database Connection (Solution That Worked For Me)

I encountered the “error establishing database connection” error in XMAPP today and learned how to fix the issue. I’ll tell you the exact steps I took to remove the error and create a local WordPress development environment on my PC. 

It all started when I decided to learn how to build a simple plugin. 

I asked Claude AI for some tips. It said I needed to create a local WordPress development environment, among other things. 

Installing XAMPP in Local Computer

Step 1: I installed XAMPP on my local computer, which took a while, and then started Apache and MySQL servers. This went smoothly, to my surprise. 

xampp control panel

Step 2: I needed to create a database so I typed localhost/phpmyadmin in the Google Chrome browser. Named the database wordpress_dev. This went smoothly, too. 

The database was empty at this point. It had to be filled with WordPress tables. 

Encountering Error Establishing Database Connection in XAMPP

Step 3: Downloaded WordPress from wordpress.org and extracted it in xampp/htdocs/wordpress.

Step 4: In Chrome, I navigated to localhost/wordpress and was asked to add database details like database name, password, username, password, database host, and database table prefix. 

I immediately encountered the “error establishing database connection” message. 

error establishing database connection xampp

Fixing Error Establishing Database Connection in XAMPP

I asked Claude AI about the error and for possible solutions. 

It suggested that the WordPress couldn’t connect with the database (created back in step 2) probably because the wp-config.php file in the WordPress folder on my local computer does not have the correct database credentials. 

I opened the wp-config-sample.php file on my local computer, and it looked like this: 

/** 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_';

SOLUTION 1

I filled in the database name, password, username, password, database host, database table prefix, and the db_collate options. Saved and closed the file. 

Also, renamed the file from wp-config-sample.php to wp-config.php.

I went back to the Chrome browser and added the same database details to the localhost/wordpress. 

SOLUTION 1.2

Encountered the error establishing database connection with a new message:

Access denied for user 'sufia'@'localhost' (using password: YES)
error establishing database connection local host xampp

Claude AI said the error had to do with indicating that the database was rejecting the connection attempt because the username did not have the necessary privileges to connect to the database.

As I mentioned earlier, the new database was empty, so I thought I needed to create a new user with the same username and password that I added in the wp-config.php file and in localhost/wordpress.

However, adding the user name caused the “bad file descriptor” 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;
add user account phpmyadmin

SOLUTION 1.3 (SUCCESS)

Claude AI suggested a few solutions. One solution was to remove the was to remove the aria_log.00000001 file from the C:\xampp\mysql\data directory in my local computer. Easy enough. I did that. 

Once again, a new user was created in the database. Success!

Next, I navigated to localhost/wordpress on Chrome and added database details. Success again!

I was asked to fill in my local website information. 

adding basic info during wordpress installation

On the next page, I logged into my local WordPress development environment using my database username and password. 

wordpress dashboard after installation

Final Thoughts

Before wrapping up, it’s worth mentioning that the fix wasn’t this straightforward. Claude AI suggested a number of fixes, and I reached this solution after eliminating other possible fixes.

You might have encountered the error due to other reasons. I highly suggest using AI to find possible solutions and implementing them one by one. 

It took me over an hour to fix this tiny issue, but I love this learning process. 

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. 

sufia banu profile pic leaves background

About the Writer

Hi, this is Sufia! I’m a seasoned writer with 6 years of experience crafting content for WordPress, WooCommerce, plugins, and themes. When not writing, I love reading, drinking coffee, meditating, working out, and spending time in nature!

Affiliate Disclosure: Some of the products and services reviewed or mentioned on this website may contain affiliate links. If you click on these links and make a purchase, I may earn a commission at no additional cost to you.

That said, please be assured that my opinions are unbiased because I do not accept payments for positive reviews. Learn more.

Leave a Comment