php/mySQL on XAMPP: password for phpMyAdmin and mysql_connect different?

php/mySQL on XAMPP: password for phpMyAdmin and mysql_connect different?

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

Stefan Bogdanescu

Founder & Senior Architect

Distinguishing phpMyAdmin Authentication from MySQL Application Credentials on XAMPP

On a typical Windows development stack like XAMPP, it is common to encounter a confusing discrepancy between two authentication mechanisms: the login required to access localhost/phpmyadmin and the credentials needed for mysql_connect('localhost', 'user', 'password'). You might set a root password via http://localhost/security, yet find that your PHP scripts cannot connect using those same details. This isn't a bug in XAMPP; it is a consequence of how the underlying MySQL server manages different types of accounts and authentication methods.

To understand why these passwords differ, you must distinguish between the user account created specifically for the web interface and the actual root system account used by your application code. When you visit the XAMPP security page to set a password, you are often modifying or creating a specific administrative user intended for the phpMyAdmin session. However, your PHP script using mysql_connect() is attempting to authenticate against the MySQL server's native root account, which may have a separate, default, or unconfigured password.

In many XAMPP installations, the root user inside the MySQL instance does not require a password by default for local connections. This is a security configuration choice made during installation to simplify initial setup. Consequently, your PHP script might connect successfully with an empty string for the password:

// Attempting to connect without a password
$conn = mysql_connect('localhost', 'root', ''); 

However, if you have set a password on the phpMyAdmin security page, that action may not have automatically updated the root user's authentication vector in the MySQL system tables (mysql.user). Instead, it might have created a new user entry or changed the access control for a specific role that phpMyAdmin recognizes but which doesn't match the raw root credentials your script expects.

To resolve this and ensure your application code uses the correct credentials, you need to directly interact with the MySQL server using the Command Line Client included in the XAMPP suite. Navigate to your XAMPP installation directory (usually C:\xampp\mysql\bin) and open a command prompt. Run the following command to launch the MySQL client without arguments:

mysql.exe

If prompted for a password, try entering an empty string or the default root password if you haven't changed it yet. Once inside the MySQL prompt, execute the SELECT statement to inspect the current authentication settings:

SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

If the result shows the mysql_native_password plugin but no specific password is set, your application can connect with an empty string. If you require a secure, non-empty password for your PHP scripts, you must explicitly create or update the root account within the MySQL CLI. Run the following command to set a strong password, replacing 'NewSecurePassword' with your choice:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword';
FLUSH PRIVILEGES;

After executing these commands, exit the prompt and update your PHP configuration file (connection.php) to include the new password. It is crucial to note that you should avoid using the root user in production environments due to its elevated privileges. A best practice for application development is to create a dedicated database user with limited permissions. For instance, create a user named app_user and grant it access only to specific databases:

CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'AppUserPassword';
GRANT ALL PRIVILEGES ON my_database.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;

Then, update your connection.php to use this restricted account. This approach isolates application logic from system-level risks and adheres to the principle of least privilege. By separating the administrative access used by phpMyAdmin from the application credentials used by your code, you maintain a clear security boundary while ensuring your development stack functions correctly.

Our network