Can’t log into phpMyAdmin: Access denied for user ‘root’@’localhost’ — How to Fix It

Featured image with a pink background, the phpMyAdmin sailboat icon overlapped by a red exclamation mark circle, and the text ‘phpMyAdmin Access Denied.’

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_password is the default plugin from MySQL 8.0.11 onwards, and modern phpMyAdmin (5.x) supports it. Many fresh installs work once root has a password set, but a system that uses auth_socket for root still rejects TCP logins.
  • MySQL 8.4 LTS (released April 2024): mysql_native_password is deprecated and disabled by default. If you try the old IDENTIFIED WITH 'mysql_native_password' syntax, the server returns ERROR 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@localhost is configured with two plugins simultaneously. It tries unix_socket first, falls back to mysql_native_password if the calling system user isn’t root. Note that MariaDB’s plugin is unix_socket, not auth_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.

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:

Terminal
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:

MySQL
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):

MySQL
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):

Terminal
sudo mysql

Confirm the current plugin and host (you’ll see one of auth_socket, unix_socket, caching_sha2_password, or mysql_native_password):

MySQL
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+:

MySQL
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.

Switching 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_password plugin is disabled. Either drop IDENTIFIED WITH as shown above, or, if a legacy client really needs the old plugin, add mysql-native-password=ON under [mysqld] in /etc/mysql/my.cnf and 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 is caching_sha2_password with 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(). The PASSWORD() 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 USER is 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.

Support DevAnswers
Written, tested and maintained by one developer. Your support keeps these guides accurate and ad-light.
Buy me a coffee

84 replies

Leave a reply

  1. Wrrisses

    the First mode worked for me, thanks!

  2. Hocine Korichi

    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

  3. Tim

    Worked smoothly. Thanks a lot.

  4. BALARO

    Merci j’ai essayé et ça marche

  5. juna

    haha thats work. thank you

  6. Jose

    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.

    1. DevAnswers

      Thanks. Article updated.

  7. Cha Cha

    Thank you so much. You save my world. You are genius. (^_^)

  8. RUDAN

    RODADNDO AQUI PERFEITAMENTE NO LINUX MINT 20

  9. Eric Schieber Jr.

    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.

  10. Adauto

    Thank you, work for me on ubuntu 20.10

  11. apriyanto

    Thank you very much. There is many instruction over internet, but combine with this instruction, its help my frustation. Thank you very much

  12. no one

    thank u
    you can use this to change phpmyadmin privileges
    GRANT ALL PRIVILEGES ON . TO ‘phpmyadmin’@’localhost’;

  13. Lisa

    THANK YOU !!!

  14. George

    Thanks, works perfectly.

  15. Hai Ngo

    Thanks a lot. Your instructions help me go through the problem solving.

  16. Rob Knol

    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

  17. Roman

    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;

    1. Subhodeep Bhattacharjee

      Thanks It’s working now…. Thanks a lot.. 🙂

    2. themerc

      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”;

  18. LXDevs
    TYSM BROH
  19. aza

    Thank you! You are generated really good and valueable content and helped me a lot.

    1. DevAnswers

      👍

  20. dssi

    Merci

    1. adam

      bonjour je suis désolé de te deranger mais jai beau chercher et tout essayer sa ne marche toujour pas..

  21. seki

    thx bro i love you greetings from Turkey

  22. Aminudin Anwar

    Great awesome..thx u so much

  23. Daniel CCM

    Thanks so much!!!

  24. Ramesh

    This document is very helpful for me.

    Thanks

  25. Faycha Anastasya

    Thank you, work for me on ubuntu 18.04 🙂

  26. Evgeniy

    article did not help!
    ubuntu 18.04 + mySQL 5.7.29

  27. Dario

    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.

  28. blue

    sudo thanks

  29. stew

    works like a charm thanks!

  30. davidw

    Merci 🙂

  31. adarka

    TOP, Thank you

  32. Prince

    thank you you really solved my problem

  33. Krimo

    Thank you it’s help me 🙂

  34. rixton

    Worked!!! Thank you very much!

    1. Nevil Chitiyo

      Thank you!

  35. Muhsin

    Thanks a lot dude. 😀

  36. GILBERTO JOSE SILVA

    Muito obrigado!
    Resolveu de vez o meu problema no MySQL 5.7.

  37. jose

    Thank you Mate!!!
    I’ve spend about 2 hours trying everything and everyforum and no one could give me a solution.

    Thanks!!!

  38. art-pl

    super, Thank you – Dzięki bardzo 🙂

  39. Llf0703

    Thank you

  40. Alexandre Labre

    thank youuu <3 <3 <3

  41. ibk

    Yep, like a charm 🙂
    Thank you very much, you fine sir!

  42. long haohong

    thanks very much

  43. swi innocent

    thanks works great

  44. Niels

    Thanks so much!

  45. pcerqueira

    Works well with phpmyadmin and mariadb ! Great, thanks !

  46. yogesh

    It works perfectly thanks

  47. Jose

    Thank you very much! <3

  48. Ady

    thanks. it’s very helpfull!

  49. mobin rajaei

    wow, thx dude, best help in the whole internet

  50. Gabriel Silveira

    It worked! Thank you so much.

  51. Abdullah

    IT worked. Thank you

  52. mohammed

    Hi dear
    thanks a lot for your advice.
    Happy new year

  53. No problem

    Thanks guy… well done!

  54. Jesus

    muchas gracias, me solucionó el problema

    1. DevAnswers

      ¡Genial!

  55. Lonnie

    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!

  56. sanjeev

    Thanks 🙂 You saved me
    Keep It up

  57. JAM

    You rock you saved my day !

  58. Sam

    Awesome information. Saved me a lot of time as a beginner. Thank you so much.

  59. Ane

    I can’t believe! I spend all day working on this. Thank you!

  60. Hardy HP

    Thanks so much for the clear guidance, simple steps given and finally…… phpmyadmin running smoothly in my Raspbian Pi.

  61. Mark

    Many many thanks.

  62. Times

    Yesssssss, so clean, so easy, works beautifully.

  63. jan

    Perfect, worked like a charm , always found mysql s trial to sort out on debian (now raspbian)

  64. tody

    thanks, you save me brother

    1. DevAnswers

      👊😎

  65. Andre

    I love you. And I’m not gay. haha

  66. RICHARD LOPEZ LUIS

    Excelente, gracias por la ayuda!!!

    1. DevAnswers

      De nada tío. 😉

  67. td17

    Thanks a bunch!

    1. DevAnswers

      Glad it helped 👍

  68. kalana

    thanx for helping

    1. DevAnswers

      👍

  69. hans

    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 🙂

    1. DevAnswers

      🙂

  70. Alan

    Thanks!
    Soluzione ovvia ma non ci avevo pensato!
    Grazie!

    1. DevAnswers

      Prego!

      1. ylan

        hey