“Error establishing a database connection” when installing WordPress on Windows 10 using WampServer

When I noticed some (not successful) hacking attempts on this blog, I tried to install WordPress locally on a Windows 10 machine (and finally did). wpbeginner, like usually, offers a nice tutorial about how to install it including all other required applications (Web server, database, PHP runtime).

Following this tutorial, and standing the pain to install tons of VC++ redistributables to get WampServer installed, after entering the database credentials during the WordPress installation, I received the error “Error establishing a database connection”.

WordPress error establishing a database connection

I tried some other credentials, but no success. Accessing the database via phpMyAdmin worked fine, so what was the issue?

wpbeginner’s post “How to Fix the Error Establishing a Database Connection in WordPress” did not helped.

Cause and Solution

The small test page wpbeginner shows in their post did not gave additional information. It only confirmed what WordPress already told me (ignoring the fact that mysqli_error also reported an error caused by a missing parameter in the code).

Error establishing a database connection

Luckily, before spending more time by searching the Internet for a solution, I had a look at the Windows application event log:

WordPress Connection Error Event Log Entry

Immediately, it was clear to me why WordPress was not able to connect. The user credentials were MySQL credentials, but WordPress (or better say the PHP runtime) tried to access the MariaDB instance, also installed by the WampServer installer.

When I ran the WampServer installer, I was not able to deselect MariaDB (deselect was disabled). But to have the local WordPress installation as close as possible to my Web installation, I also installed MySQL. Obviously, the MariaDB was using the ‘default’ database connection port, while MySQL was using a non-common port.

WampServer MySQL port

As the WampServer menu shows the port used by MySQL, it was easy to set the proper database credentials by adding the port to the database host name.

WordPress setup connection with port

WordPress was happy, and I was able to complete the installation.

WordPress ready to install


wpbeginner’s tutorial “How to Install WordPress on your Windows Computer Using WAMP
wpbeginner|s post “How to Fix the Error Establishing a Database Connection in WordPress
WampServer on SourceForge