Access denied for user ‘root’@’localhost’

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

Last updated on

You’ve installed phpMyAdmin but cannot log in using the root account.

mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'

In MySQL 5.7 and above, root login requires sudo privileges and phpMyAdmin will not be able to use root credentials.

It’s also not recommended that you allow the root account to be accessible remotely via phpMyAdmin as bots and hackers scan for these accounts continuously.

Instead, create a new superuser account with a different username.

In terminal, log in to MySQL as root. You may have created a root password when you installed MySQL for the first time or the password could be blank, in which case you can just press ENTER when prompted for a password. If you have forgotten your root password, you can always Reset the MySQL Root Password.

sudo mysql -p -u root

Now add a new MySQL user with the username of your choice. In this example we are calling it pmauser (for phpmyadmin user). Make sure to replace  password_here with your own. You can generate a password here.

The % symbol here tells MySQL to allow this user to log in from anywhere remotely. If you wanted heightened security, you could replace this with an IP address.

CREATE USER 'pmauser'@'%' IDENTIFIED BY 'password_here';

Now we will grant superuser privilege to our new user.


You should now be able to access phpMyAdmin using this new user account.

Hope this helps! 😀

Let me know in the comments if this helped. Follow me @DevAnswers or read more.

1 Star2 Stars3 Stars4 Stars5 Stars 4.88 (34 votes)


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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces

33 replies

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 so much for the clear guidance, simple steps given and finally…… phpmyadmin running smoothly in my Raspbian Pi.

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

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 🙂