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