Problems with creation of database DVWA

Problems with creation of database DVWA

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Debugging Database Connection Failures in DVWA

When attempting to launch the Damn Vulnerable Web App (DVWA) on a local XAMPP stack, encountering a generic mysql_error() or a message stating "Could not connect to the database" is a frequent blocker. This issue often stems from a mismatch between how the application is configured and the actual state of your MySQL server environment.

The error log typically points directly to the configuration file located at /htdocs/dvwa/config/config.inc.php. The default settings provided in this file usually assume a pristine installation where the database user is root with an empty or specific password like p@ssw0rd. If you have modified your MySQL root password during the XAMPP setup, or if you are running a version of PHP and MySQL where the security defaults differ, the connection will fail immediately.

A common misconception when troubleshooting this specific error is that simply changing the host parameter from localhost to 127.0.0.1 will resolve the issue. While localhost can sometimes trigger socket-based connections versus TCP/IP depending on driver configuration, swapping these values rarely fixes a credentials mismatch or a missing database definition. The error persists because the authentication handshake fails before the host resolution becomes the primary concern.

To resolve this, you must first verify that the MySQL service is actually running and listening. On Windows with XAMPP, this means ensuring the Apache and MySQL modules are active in the Control Panel. If they are stopped, no amount of configuration tweaking will allow PHP to establish a session.

Once the server is confirmed to be running, inspect the credentials defined in config.inc.php. If your XAMPP installation has a secure root password set (which is increasingly common due to security patches), update the $_DVWA['db_password'] variable to match that exact string. Do not guess the password; retrieve it from the XAMPP configuration file or the MySQL user table if you are unsure, though checking the config is the standard first step.

After correcting the credentials, you need to ensure the target database exists. The DVWA installer script attempts to create a database named dvwa upon first access. If the script fails due to connection errors, that database will never be created. You can bypass the web interface for this specific task by connecting directly to MySQL via the command line or the XAMPP Manager console.

Run the following SQL commands to manually initialize the environment:

CREATE DATABASE dvwa;
USE dvwa;
CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'p@ssw0rd';
GRANT ALL PRIVILEGES ON dvwa.* TO 'dvwa'@'localhost';
FLUSH PRIVILEGES;

If you require a different password, replace p@ssw0rd in the commands above and then update your config.inc.php to match. Once the database schema is manually created and the user privileges are flushed, reload the DVWA dashboard. The connection should now establish successfully without triggering the mysql_error() exception.

It is also worth noting that if you are running a very recent version of XAMPP or PHP, there may be compatibility issues with older DVWA versions regarding PDO driver settings. Ensure your config.inc.php does not inadvertently disable extensions required for MySQL connectivity, though the standard configuration usually handles this automatically. By aligning your database credentials and ensuring the schema exists manually, you bypass the installer's dependency on web-based scripting for initial setup.

Our network