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

Can’t log into phpMyAdmin: mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’

Last updated on | 84 replies

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’re trying to log in under a different account and seeing “Access denied for user (using password: YES)”.
    See article: MySQL Rejecting Correct Password

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 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 in GRANT.
  • Alternative Queries: If ALTER USER is not recognized or fails, try UPDATE mysql.user ... and then FLUSH PRIVILEGES.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

84 replies

Leave a reply

Your email address will not be published. Required fields are marked *

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

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

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

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

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

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

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