Introduction
If you’re seeing mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'
when trying to log into phpMyAdmin, it usually means there’s a configuration or authentication issue with MySQL or MariaDB. This error may occur for any of the following reasons:
- Due to security changes in MySQL 5.7 / MySQL 8+ (or MariaDB 10.4+), you can no longer log into phpMyAdmin using the root account.
See section: MySQL 5.7 / MySQL 8+
- You’ve forgotten your MySQL root password.
See article: How To Reset the MySQL Root Password
- The
host
value for root is preventing phpMyAdmin access.
See article: Understanding MySQL Users and Hosts
- You’re trying to log in under a different account and seeing “Access denied for user (using password: YES)”.
See article: MySQL Rejecting Correct Password
- If you’re on MySQL 5.6 or below.
See section: MySQL 5.6 and below
MySQL 5.7 / MySQL 8+ (and MariaDB 10.4+)
In MySQL 5.7, MySQL 8, and MariaDB 10.4+, the root user often authenticates via auth_socket
, socket
, or caching_sha2_password
instead of mysql_native_password
. This blocks external programs like phpMyAdmin from logging in as root unless you change it. You can either create a new superuser (recommended) or switch the root plugin to mysql_native_password
.
Choose one of the following methods:
Method 1: Create a New Superuser for phpMyAdmin
1. Open a terminal and log into MySQL as root:
sudo mysql -p -u root
Enter the password for your MySQL root account if prompted. If you’ve forgotten it, see How to Reset the MySQL Root Password.
2. Create a new MySQL user named pmauser
(or any username you prefer) and set a password of your choice:
CREATE USER 'pmauser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password_here';
3. Grant all privileges on every database, along with the WITH GRANT OPTION
to allow creating other users or granting privileges:
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost' WITH GRANT OPTION;
4. You can now log in to phpMyAdmin using pmauser
. If you see “Access denied for user (using password: YES)”, see MySQL Rejecting Correct Password.
If you see the error “Failed to set session cookie. Maybe you are using HTTP instead of HTTPS”, see this article.
Method 2: Change root Authentication Method
If you absolutely need to log into phpMyAdmin as root, switch the root account from auth_socket
, socket
, or caching_sha2_password
to mysql_native_password
. This ensures compatibility with phpMyAdmin (especially older PHP versions).
1. Log into MySQL via terminal:
sudo mysql
If you see “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”, add -p -u root
:
sudo mysql -p -u root
2. Check which plugin root is using (and confirm host
is localhost
or %
):
SELECT user,plugin,host FROM mysql.user WHERE user = 'root';
You may see auth_socket
, socket
, or caching_sha2_password
. Also note the host
if you want root access from specific hosts or any host (%
).
3. Update the plugin to mysql_native_password
and set a new password. If you see ERROR 1064, you likely have mismatched quotes (use straight single quotes ' '
):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'enter_password_here';
FLUSH PRIVILEGES;
If ALTER USER
fails for you, try manually updating the mysql.user
table, then FLUSH PRIVILEGES;
:
UPDATE mysql.user
SET plugin = 'mysql_native_password',
authentication_string = PASSWORD('enter_password_here')
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
You should now be able to log in to phpMyAdmin as root.
MySQL 5.6 and below
In MySQL 5.6 or older versions, you can typically log in to phpMyAdmin as root without extra steps. If it still doesn’t work, it might be because:
- You’ve forgotten your root password.
Reset the MySQL Root Password
- The
host
value for root is blocking phpMyAdmin access.
Understanding MySQL Users and Hosts
- You’re trying to use a non-root account with insufficient privileges.
MySQL Rejecting Correct Password
You can still create a new superuser the same way as in MySQL 5.7/8+ if you prefer.
Visitor Comments & Additional Tips
A few extra hints based on user feedback:
- ERROR 1064 (42000): Usually caused by curly or mismatched quotes. Double-check you’re using straight single quotes
' '
. - WITH GRANT OPTION: If you want the user to create other users or grant privileges, add
WITH GRANT OPTION
inGRANT
. - Alternative Queries: If
ALTER USER
is not recognized or fails, tryUPDATE mysql.user ...
and thenFLUSH PRIVILEGES
.
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
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