phpMyAdmin: Access denied for user 'root'@'localhost'
#1045 - Access denied for user 'root'@'localhost' (using password: NO)Short answer
MySQL refused the root login. The message shows whether a password was sent: using password: NO means phpMyAdmin sent none. Log in with the mysql client first. If that fails, the password or account is wrong; if it works, fix the credentials in phpMyAdmin's config. As a last step, reset the root password.
Fix it fast
1Find out which cause you have
Skip phpMyAdmin and log in with the MySQL client. Its result tells you whether the problem is the server account or phpMyAdmin's settings. The end of the message tells you whether a password was sent.
mysql -u root -p mysql -u root -p -h 127.0.0.12Match what you see, then jump to its fix
- 1
(using password: NO), or (using password: YES) with a password you believe is rightA root password exists but none (or the wrong one) is being sentFix - 2
The error appears right on opening phpMyAdmin, before any login formconfig.inc.php holds credentials that no longer matchFix - 3
mysql -u root -p works, but connecting with -h 127.0.0.1 or from phpMyAdmin failsThe account matched is not the one you think (localhost vs 127.0.0.1)Fix - 4
No known password works and no other admin account existsThe root password is lost and has to be resetFix
- 1
What does the error look like?
#1045 - Access denied for user 'root'@'localhost' (using password: NO)#1045 - Access denied for user 'root'@'localhost' (using password: YES)mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost'
Cause 1 of 4
A root password exists but none (or the wrong one) is being sent
1Check
A fresh install usually sets a root password. Logging in without one fails with this error. Old passwords left in an option file are also read by clients, so test with option files bypassed.
mysql -u root -p
mysqladmin --no-defaults -u root -p version2Fix
Use the real password in phpMyAdmin's login form. If you do not know it, reset it (last cause below).
# phpMyAdmin login page: user root, the real password3Verify
The mysql client login succeeds, and so does phpMyAdmin's.
mysql -u root -p -e 'SELECT CURRENT_USER();'Confirmed by dev.mysql.com
Cause 2 of 4
config.inc.php holds credentials that no longer match
1Check
phpMyAdmin authenticates against the MySQL server you use. Its FAQ lists wrong controluser and controlpass values as a cause of Access denied.
grep -n -E "controluser|controlpass|auth_type|\[.host.\]" /etc/phpmyadmin/config.inc.php2Fix
Correct the user and password in config.inc.php, or remove the control user lines if you do not use that feature, and reload the page.
<?php
// config.inc.php
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = '127.0.0.1';3Verify
The login form shows and signs in.
mysql -u root -p -h 127.0.0.1 -e 'SELECT 1;'Confirmed by docs.phpmyadmin.net
Cause 3 of 4
The account matched is not the one you think (localhost vs 127.0.0.1)
1Check
localhost normally means a Unix socket connection; 127.0.0.1 forces TCP. Accounts are matched by user and host, so 'root'@'localhost' and an account for another host are different. Ask the server which row matched.
SELECT USER(), CURRENT_USER();
SELECT User, Host, plugin FROM mysql.user WHERE User = 'root';2Fix
Use the host that matches an existing account, or create the account for the host you really connect from. Do not use '%' for root.
CREATE USER 'app'@'127.0.0.1' IDENTIFIED BY 'a-strong-password';
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'app'@'127.0.0.1';3Verify
Login over TCP works for that account.
mysql -u app -p -h 127.0.0.1 appdb -e 'SELECT 1;'Confirmed by dev.mysql.com
Cause 4 of 4
The root password is lost and has to be reset
1Check
You need shell access to the server. The manual's recommended method restarts MySQL with an init file that holds one ALTER USER statement.
mysql --version2Fix
Stop MySQL, write the init file, start the server with it, then delete the file and restart normally. Replace the sample password with your own.
# contents of /home/me/mysql-init (one line)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
mysqld --init-file=/home/me/mysql-init &3Verify
Log in with the new password, then remove the init file and restart MySQL normally.
mysql -u root -p
rm /home/me/mysql-initConfirmed by dev.mysql.com
How do I stop it coming back?
- Use a named MySQL account with limited rights for applications, and keep root for administration.
- Keep phpMyAdmin behind a VPN, an allow-list or HTTP auth, never open to the internet with root.
- Store the root password in a password manager when the server is created.
- Use localhost or 127.0.0.1 consistently in app config so one account matches.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fixDatabases
DBeaver cannot verify the MySQL server certificate
unable to find valid certification path to requested target
DBeaver's MySQL driver is checking the server certificate and Java does not trust the CA that signed it.
2 causes, each with a fix