Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

$ ./mysqladmin -u root -p 'redacted'

Enter password:

mysqladmin: connect to the server at 'localhost' failed error:

'Access denied for user 'root'@'localhost' (using password: YES)'

How can I fix this?

3 Answers

0 votes
by (40.7k points)

To fix MySQL Error: : 'Access denied for user 'root'@'localhost', you should follow these steps:

Step 1: Open and Edit /etc/my.cnf or /etc/mysql/my.cnf, according to your distro.

Step 2: Add skip-grant-tables which is under [mysqld]

Step 3: Now, Restart Mysql

You must be able to login to mysql now by using the below command mysql -u root -p

Run mysql> flush privileges;

Now, set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; and go back to /etc/my.cnf and remove/comment skip-grant-tables

Again, Restart Mysql, now you can login with the new password 

mysql -u root -p

You can master these queries and become proficient in SQL queries by enrolling in an industry-recognized SQL certification.

0 votes
by (1.9k points)

To resolve the "Access denied for user 'root'@'localhost'" error in MySQL, start by opening the MySQL configuration file, which is usually located at /etc/my.cnf or /etc/mysql/my.cnf, depending on your Linux distribution.

Next, you’ll want to add the line skip-grant-tables under the [mysqld] section. This change will allow you to log in without checking user permissions.

After making this change, restart the MySQL service to apply the modifications. You should now be able to log in without a password by using the command mysql -u root.


Once you're logged in, run FLUSH PRIVILEGES; to refresh the permissions. Next, change the root user’s password by entering ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';.

After that, head back to the MySQL configuration file and either delete or comment out the line that says skip-grant-tables. Finally, restart the MySQL service to apply these changes.

Once the service is back up, you can log into your MySQL server with the new password by using the command mysql -u root -p. By doing this, you’ll be able to access your MySQL server as the root user again.

0 votes
by (1.8k points)
  • To resolve the "Access denied for user 'root'@'localhost'" error in MySQL, start by opening the MySQL configuration file, which is usually located at /etc/my.cnf or /etc/mysql/my.cnf, depending on your Linux distribution.
  • Next, you’ll want to add the line skip-grant-tables under the [mysqld] section. This change will allow you to log in without checking user permissions.
  • After making this change, restart the MySQL service to apply the modifications. You should now be able to log in without a password by using the command mysql -u root.
  • Once you're logged in, run FLUSH PRIVILEGES; to refresh the permissions. Next, change the root user’s password by entering ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';.
  • After that, head back to the MySQL configuration file and either delete or comment out the line that says skip-grant-tables. Finally, restart the MySQL service to apply these changes.
  • Once the service is back up, you can log into your MySQL server with the new password by using the command mysql -u root -p. By doing this, you’ll be able to access your MySQL server as the root user again.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...