We may earn a referral fee at no additional cost to you when you shop through the links on this page.
Trying to log into phpMyAdmin and getting mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'? On modern MySQL and MariaDB, the root account is often unreachable from a web client like phpMyAdmin until you adjust how it authenticates. This DevAnswers walkthrough covers two reliable fixes that work across MySQL 5.7, 8.0, 8.4 LTS, 9.x, and MariaDB 10.4+ (5.7 reached EOL in October 2023; the same simple IDENTIFIED BY syntax shown for MariaDB and MySQL 8.4 below works on it).
Introduction
The error means phpMyAdmin’s web request reaches the database as the web server’s PHP process, not as the system root user, so socket-based authentication rejects it. The fix is either to create a dedicated phpMyAdmin user (recommended) or to switch root itself onto a password-based plugin. Both fixes work on every supported MySQL and MariaDB version; the next section explains what changed in each.
Modern MySQL and MariaDB defaults: why root can’t log in to phpMyAdmin
What’s blocking root depends on which database you’re running, because each line ships root with a different default authentication plugin. Three eras matter today:
- MySQL 8.0–8.3:
caching_sha2_passwordis the default plugin from MySQL 8.0.11 onwards, and modern phpMyAdmin (5.x) supports it. Many fresh installs work onceroothas a password set, but a system that usesauth_socketforrootstill rejects TCP logins. - MySQL 8.4 LTS (released April 2024):
mysql_native_passwordis deprecated and disabled by default. If you try the oldIDENTIFIED WITH 'mysql_native_password'syntax, the server returnsERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded. MySQL 9.x removes the plugin entirely. - MariaDB 10.4+ (including 10.6 LTS, 10.11 LTS, 11.x):
root@localhostis configured with two plugins simultaneously. It triesunix_socketfirst, falls back tomysql_native_passwordif the calling system user isn’troot. Note that MariaDB’s plugin isunix_socket, notauth_socket(that’s MySQL’s name).
In each of these cases phpMyAdmin’s connection arrives as the web server’s PHP user (typically www-data), not as the system root user, so socket-based authentication fails and the password-based fallback either isn’t set or isn’t the active plugin. Both fixes below resolve that.
Method 1: Create a Separate phpMyAdmin User (Recommended)
Cleanest fix, works on every supported MySQL and MariaDB version, and avoids touching root at all. Open a terminal and log into the database as root:
sudo mysql
That uses socket authentication (the default for root on most modern installs) and won’t prompt for a password. If you’re already logged in as the system root user, drop the sudo and just run mysql. If root already has a password set on a non-socket plugin, use sudo mysql -p -u root instead and enter the password (or reset it if you’ve forgotten). At the prompt, create a new user (devans_pma here, but choose any name you like) with a strong, randomly generated password:
CREATE USER 'devans_pma'@'localhost' IDENTIFIED BY 'enter_password_here';
Notice there’s no IDENTIFIED WITH 'plugin_name' clause. The server applies its default password-based plugin (on MySQL 8.4 that’s caching_sha2_password) and current phpMyAdmin handles it. Now grant full privileges with the grant option (so the user can also create databases and other users):
GRANT ALL PRIVILEGES ON *.* TO 'devans_pma'@'localhost' WITH GRANT OPTION;
Be aware this makes devans_pma root-equivalent inside the database server: anyone who logs into phpMyAdmin with it controls every database and can create new users. If the account only needs to manage one application’s database, scope the grant instead, for example GRANT ALL PRIVILEGES ON appdb.* TO 'devans_pma'@'localhost'; and skip WITH GRANT OPTION.
Log into phpMyAdmin with devans_pma and the password you just set. If the login screen returns Access denied for user (using password: YES), see MySQL rejecting a correct password. If you land on a session-cookie warning instead, see this fix.
Method 2: Change root’s Authentication Plugin
If you specifically need to log into phpMyAdmin as root, switch root‘s plugin to a password-based one. Log into the MySQL or MariaDB shell as in Method 1 (sudo mysql, or sudo mysql -p -u root if root already has a password):
sudo mysql
Confirm the current plugin and host (you’ll see one of auth_socket, unix_socket, caching_sha2_password, or mysql_native_password):
SELECT user, plugin, host FROM mysql.user WHERE user = 'root';
Now run ALTER USER on every supported version. The same simple syntax (no IDENTIFIED WITH) sets a password and applies the server’s default plugin: caching_sha2_password on MySQL 8.0+ (modern phpMyAdmin handles it) and mysql_native_password on MariaDB 10.4+:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'enter_password_here';
On MySQL 8.0–8.3 you can still pin the plugin explicitly with IDENTIFIED WITH mysql_native_password if a legacy client requires it, but that’s a downgrade; prefer the default unless you have a specific reason. Do not use the explicit-plugin form on MySQL 8.4 LTS or 9.x: 8.4 returns ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded, and 9.x has removed the plugin entirely.
root away from socket authentication means anyone who obtains the password can log in as root from the box itself, including through phpMyAdmin or any compromised local web app. The account’s localhost host part still blocks direct remote logins (unless a separate root@'%' account exists), but keep bind-address restricted and the port firewalled as defence in depth, or stick with Method 1 instead. Troubleshooting and Tips
- ERROR 1064 (42000) near ‘IDENTIFIED’: usually mismatched or curly quotes pasted from a styled document. Retype the statement using straight single quotes (
'). - ERROR 1524 (HY000) on MySQL 8.4 LTS: the
mysql_native_passwordplugin is disabled. Either dropIDENTIFIED WITHas shown above, or, if a legacy client really needs the old plugin, addmysql-native-password=ONunder[mysqld]in/etc/mysql/my.cnfand restart the service. This workaround does not apply to MySQL 9.x: the plugin is no longer present in the server, so the only option there iscaching_sha2_passwordwith a current client. - Authentication method unknown to the client: the client connecting to MySQL doesn’t support
caching_sha2_password. The cleaner fix is to upgrade phpMyAdmin rather than downgrade the database plugin. - Don’t use
UPDATE mysql.user ... PASSWORD(). ThePASSWORD()function was removed in MySQL 8.0.11 (April 2018), so the legacy fallback recipe you’ll find in older Stack Overflow answers fails on every modern MySQL.ALTER USERis the supported path on both MySQL and MariaDB.
Conclusion
Method 1 is the right default for almost every setup: it leaves root on its hardened socket-based plugin and gives phpMyAdmin a dedicated login it can actually use. Reach for Method 2 only when you genuinely need root over the wire, and pair it with the firewall and bind-address controls in our phpMyAdmin install guide.
the First mode worked for me, thanks!
Hi,
I got an error when executiong this:
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘enter_password_here’;
ERROR 1064 (42000): You have an error in your SQL syntax;
Any help, please
Regards
Worked smoothly. Thanks a lot.
Merci j’ai essayé et ça marche
haha thats work. thank you
You need to also provide the ‘with grant option’ if you use method 1.
GRANT ALL PRIVILEGES ON . TO ‘pmauser’@’localhost’ WITH GRANT OPTION;
Otherwise, pmauser can not create new users and grant them options to other databases.
Thanks. Article updated.
Thank you so much. You save my world. You are genius. (^_^)
RODADNDO AQUI PERFEITAMENTE NO LINUX MINT 20
Ayy bro just wanted to say i was really stuck, really appreciate you. Thanks a bunch man. Much love. Crazy world we live in today. Wish people would just come together.
Thank you, work for me on ubuntu 20.10
Thank you very much. There is many instruction over internet, but combine with this instruction, its help my frustation. Thank you very much
thank u
you can use this to change phpmyadmin privileges
GRANT ALL PRIVILEGES ON . TO ‘phpmyadmin’@’localhost’;
THANK YOU !!!
Thanks, works perfectly.
Thanks a lot. Your instructions help me go through the problem solving.
Super solution! thank you very mutch! After weeks finaly sql is ( allmost ) fixed. Now I can access myphpadmin againand I hope I can restore my old database. Thank you very mutch for sharing this solution
Method 2 didn’t work for me. So I’ve found another one that worked.
mysql> UPDATE mysql.user SET plugin = ‘mysql_native_password’, authentication_string = PASSWORD(‘changeme’) WHERE User = ‘root’;
mysql> FLUSH PRIVILEGES;
Thanks It’s working now…. Thanks a lot.. 🙂
double quote was needed for anyone who is stuck here
UPDATE mysql.user SET plugin = “mysql_native_password”, authentication_string = PASSWORD(“changeme”) WHERE User = “root”;
Thank you! You are generated really good and valueable content and helped me a lot.
👍
Merci
bonjour je suis désolé de te deranger mais jai beau chercher et tout essayer sa ne marche toujour pas..
thx bro i love you greetings from Turkey
Great awesome..thx u so much
Thanks so much!!!
This document is very helpful for me.
Thanks
Thank you, work for me on ubuntu 18.04 🙂
article did not help!
ubuntu 18.04 + mySQL 5.7.29
Thank you so much for this. I’m a noob and been banging my head for an hour on a NEW FREAKING installation. Your rage comig made it all that much better.
sudo thanks
works like a charm thanks!
Merci 🙂
TOP, Thank you
thank you you really solved my problem
Thank you it’s help me 🙂
Worked!!! Thank you very much!
Thank you!
Thanks a lot dude. 😀
Muito obrigado!
Resolveu de vez o meu problema no MySQL 5.7.
Thank you Mate!!!
I’ve spend about 2 hours trying everything and everyforum and no one could give me a solution.
Thanks!!!
super, Thank you – Dzięki bardzo 🙂
Thank you
thank youuu <3 <3 <3
Yep, like a charm 🙂
Thank you very much, you fine sir!
thanks very much
thanks works great
Thanks so much!
Works well with phpmyadmin and mariadb ! Great, thanks !
It works perfectly thanks
Thank you very much! <3
thanks. it’s very helpfull!
wow, thx dude, best help in the whole internet
It worked! Thank you so much.
IT worked. Thank you
Hi dear
thanks a lot for your advice.
Happy new year
Thanks guy… well done!
muchas gracias, me solucionó el problema
¡Genial!
I’ve been looking for two days for an answer. One post even suggested I completely uninstall MySQL and start over. This one worked perfectly. Apparently each version of MySQL has their own syntax. Mine never recognized the syntax from the other posts but took this one completely. I now have a password for my root as well. Thank You!
Thanks 🙂 You saved me
Keep It up
You rock you saved my day !
Awesome information. Saved me a lot of time as a beginner. Thank you so much.
I can’t believe! I spend all day working on this. Thank you!
Thanks so much for the clear guidance, simple steps given and finally…… phpmyadmin running smoothly in my Raspbian Pi.
Many many thanks.
Yesssssss, so clean, so easy, works beautifully.
Perfect, worked like a charm , always found mysql s trial to sort out on debian (now raspbian)
thanks, you save me brother
👊😎
I love you. And I’m not gay. haha
Excelente, gracias por la ayuda!!!
De nada tío. 😉
Thanks a bunch!
Glad it helped 👍
thanx for helping
👍
THANK U SO NUCH IT WORK !!!!!!!!!!!!!!!
I always can login as root before , but now in Ubuntu 18.04 it fail it not work.
Great a new user work fine 🙂
🙂
Thanks!
Soluzione ovvia ma non ci avevo pensato!
Grazie!
Prego!
hey