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