phpMyAdmin #1045 “Access denied for user root@localhost”: the fix
“mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)”. MySQL received phpMyAdmin’s login and rejected it, so the user, password or server in phpMyAdmin’s config does not match the database. It usually starts after someone set a root password, after a second MySQL install took over port 3306, or after an upgrade changed how MySQL checks passwords. The end of the message tells you which.
- Platform
- Windows 10/11 with XAMPP in C:\xampp (the checks apply to any phpMyAdmin)
- Time
- About 10 minutes
- You need
- Write access to phpMyAdmin’s config.inc.php (C:\xampp\phpMyAdmin\config.inc.php in XAMPP)
- A Command Prompt, to test the login and reset the password
XAMPP paths are for the default C:\xampp install; EnvKit details checked against 0.33.0-beta.56 on 2026-10-29.
Step 1: Read the end of the message
using password: NOmeans phpMyAdmin sent no password, but root has one.using password: YESmeans it sent a password and MySQL rejected it: the password is wrong, or phpMyAdmin is talking to a different server than you think.If the code is #2002 or #2054 instead of #1045, the cause is different; both are covered under troubleshooting below.
Step 2: Test the login outside phpMyAdmin
Use the MySQL client that came with the server. At the password prompt, press Enter to try an empty password, or type the one you think is right. If a password works here, phpMyAdmin only needs that password in its config. If nothing works, reset it (step 5).
Command Prompt C:\xampp\mysql\bin\mysql.exe -u root -p -h 127.0.0.1 -P 3306Step 3: Check config.inc.php
XAMPP’s phpMyAdmin logs in automatically with the user and password written in
config.inc.php. Withauth_typeset toconfig,passwordmust match root’s real password. Setauth_typetocookieto get a login form instead, and type the password when you open phpMyAdmin; cookie mode also needs a 32-characterblowfish_secret.Save the file and reload phpMyAdmin. Nothing needs a restart.
C:\xampp\phpMyAdmin\config.inc.php $cfg['Servers'][$i]['auth_type'] = 'config'; // or 'cookie' for a login form $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = 'your-root-password'; $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['port'] = '3306'; $cfg['Servers'][$i]['AllowNoPassword'] = true;Step 4: Make sure phpMyAdmin reaches the right server
If another MySQL is installed (the
MySQL80service from MySQL Installer, WampServer, Laragon), it may be the one listening on 3306, with its own root password. Find the PID on the port and look it up. If it is not XAMPP’smysqld.exe, stop that service in services.msc, or move XAMPP’s MySQL to another port inmy.iniand set the sameportinconfig.inc.php.Command Prompt netstat -ano | findstr LISTENING | findstr :3306 tasklist /FI "PID eq 1234"Step 5: Reset a forgotten root password
Stop MySQL in the Control Panel. Start it by hand without the privilege tables, so root can log in with no password, and set a new password from a second window. While it runs this way anyone on this computer can log in, so finish in one go.
Command Prompt REM Window 1: start MySQL without the privilege tables C:\xampp\mysql\bin\mysqld.exe --defaults-file=C:\xampp\mysql\bin\my.ini --skip-grant-tables REM Window 2: set the new password, then stop the server C:\xampp\mysql\bin\mysql.exe -u root FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password'; exit C:\xampp\mysql\bin\mysqladmin.exe -u root -p shutdownStep 6: MySQL 8 and the authentication plugin
MySQL 8 creates users with
caching_sha2_password. A PHP or phpMyAdmin too old for it fails with #2054 “The server requested authentication method unknown to the client”. Update PHP and phpMyAdmin first. On MySQL 8.0 you can switch root back to the older plugin as a stopgap, but MySQL 8.4 turnsmysql_native_passwordoff by default and MySQL 9 removes it. MariaDB, which XAMPP ships, usesmysql_native_passwordby default.MySQL 8.0 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';Step 7: Or use EnvKit’s MySQL and phpMyAdmin
EnvKit is a free app that installs MySQL or MariaDB, phpMyAdmin and the rest of a PHP stack. Stop XAMPP’s MySQL first so the two do not compete for port 3306.
Or install from the terminalirm https://envkit.net/install.ps1?c=guide-phpmyadmin-access-denied-1045 | iexStep 8: How EnvKit’s phpMyAdmin logs in
EnvKit writes phpMyAdmin’s
config.inc.phpitself: aconfiglogin asrootwith an empty password on 127.0.0.1 and the port EnvKit’s MySQL uses, so phpMyAdmin opens without a login form. Open it from the Databases page with Open phpMyAdmin.If you give root a password, enter it in Services → phpMyAdmin → Settings under MySQL password (config auth), or set Auth type to cookie to get the login form back. A database port you change in EnvKit is carried into phpMyAdmin’s config.
If something goes wrong
- #2002 “No connection could be made because the target machine actively refused it”
- Nothing is listening on the host and port phpMyAdmin uses. Start MySQL, and check that the
portinconfig.inc.phpmatches theport=line inmy.ini. - “Connection for controluser as defined in your configuration failed”
- That is the
pmacontrol user phpMyAdmin uses for its extra features, separate from your root login. Fix itscontroluserandcontrolpassinconfig.inc.php, or comment both lines out to run without those features. - Root works in the terminal but not in phpMyAdmin
- MySQL treats
root@localhostand[email protected]as separate accounts that can have different passwords. Compare thehostinconfig.inc.phpwith the address you used in the terminal, and set the same password on both accounts.