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

MySQL 5.7 and above

Since October 2015, root now requires sudo privileges in MySQL 5.7+ and phpMyAdmin will not be able to use root credentials.

If you are trying to log into phpMyAdmin using an account other than root but you are getting an error “Access denied for user (using password: YES)”, please see this article: MySQL Rejecting Correct Password “Error 1045: Access denied for user (using password: YES)”

If you want to create a new superuser account that you can use to administer MySQL through phpMyAdmin, read on.

Creating a Superuser for phpMyAdmin

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. Make sure to replace password_here with your own. You can generate a strong password here.

The command below will create a new user called pmauser (call this what you like) which can access the MySQL server from localhost with the password password_here.

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

Now we will grant superuser privilege to our new user pmauser.

GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost' WITH GRANT OPTION;

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

If you are getting an error for this new user “Access denied for user (using password: YES)”, please read this article.

Hope this helps! 😀

MySQL 5.6 and below

If you have forgotten your root password, you can try reset it via command line.

You could also create a new user for phpMyAdmin by following the step for MySQL 5.7 and above (the commands are the same).

Upgrading phpMyAdmin

While you’re here, you may be interested in an article I wrote on manually upgrading phpMyAdmin. Since the release of Ubuntu 18.04, the repositories have been slow to update with the latest version of phpMyAdmin causing some compatibility issues, so make sure you have the latest version:

MySQL Backups

Are you backing up your MySQL databases? I’ve written a detailed guide on how to automatically dump and archive databases using mysqldump and cron:

Let me know in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 4.73 (51 votes)

Leave a Reply

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

52 replies

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.

Thank you Mate!!!
I’ve spend about 2 hours trying everything and everyforum and no one could give me a solution.

Thanks!!!

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.

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 🙂