access denied mysql ubuntu

Access denied for user ‘root’@’localhost’ (using password: NO Ubuntu)

Till Ubuntu 12.04, users were able to log into root user in MySQL. But starting Ubuntu 12.04, this feature has been disabled and when you try to log into MySQL as root user, you will get an error saying ‘How to Fix Access denied for user ‘root’@’localhost’ (using password: NO Ubuntu)’. Previously, root access was blocked from remote systems. But now, even local users are unable to login as root in MySQL. This has been done for security purposes to prevent hackers from logging into your MySQL database, once they have access to your system. In this article, we will learn how to overcome this hurdle in Ubuntu.

How to Fix Access denied for user ‘root’@’localhost’ (using password: NO Ubuntu)

Generally, users were able to log into root user from local machine with the following command, where <password> was your root user’s password.

$ sudo mysql -u root -p <password>

But now the above command will give you access denied error.

So if you are accessing via localhost, you need to enter the following command instead, omitting the <password>.

$ sudo mysql -u root -p

You will be prompted for root password, which you can enter and login successfully as root user. This has been done so that the user has to manually enter the password, and automated scripts cannot easily log into MySQL root by simply entering the old command that carried the password. Also it avoids the security vulnerability of exposing passwords publicly in commands.

If you are logging in from remote systems, use the following command, where you specify the target MySQL database with -h option.

$ mysql -uroot -p

Here also you will be prompted to enter root password. On entering the correct password, you will be able to login successfully. In this case, you need to also ensure that your MySQL database allows remote access.

In this article, we have learnt how to access MySQL as root user in Ubuntu, starting 12.04. You can apply this method to all subsequent Ubuntu systems.

Also read:

How to Remove NaN from Python List
Delete All Except One File in Linux
How to Mount Remote Directory or Filesystem in Linux
How to Check Bad Sectors in Linux
How to Convert Markdown to HTML

Leave a Reply

Your email address will not be published.