Software⏱️ 3 min read📅 2026-06-19

How to Fix: I am getting following error in Ubuntu 18 although I haven't set any password for SQL

Ubuntu 18.0 SQL access denied error due to missing password.

Quick Answer: Try using the "--skip-password" option when connecting to MySQL.

The error message 'Access denied for user 'root'@'localhost'(using password: YES)' appears when you try to connect to MySQL using the 'mysql' command, but you haven't set a password for the SQL user. This issue affects users who are trying to access their MySQL databases without setting up a password.

This error can be frustrating because it prevents users from accessing their data and performing necessary operations on their databases. In this guide, we will walk through the possible causes of this error and provide two methods to resolve it.

💡 Why You Are Getting This Error

  • The primary reason for this error is that MySQL requires a password for the 'root' user when connecting from localhost. Even if you haven't set a password explicitly, MySQL assumes one by default. This can be changed by editing the MySQL configuration file.
  • An alternative cause could be that the MySQL server is not configured to allow root login from localhost. If this is the case, you may need to adjust your MySQL configuration or seek assistance from your system administrator.

🔧 Proven Troubleshooting Steps

Editing the MySQL Configuration File

  1. Step 1: Open the MySQL configuration file in a text editor using the command 'sudo nano /etc/mysql/my.cnf'.
  2. Step 2: Locate the line that starts with '[mysqld]' and add the following line at the end of it: `skip-grant-tables`. This tells MySQL to skip password checking for root users.
  3. Step 3: Save and close the file. Then, restart the MySQL service using the command 'sudo service mysql restart' or 'sudo systemctl restart mysql'.

Setting a Password for the Root User

  1. Step 1: Open a terminal as the root user using the command 'sudo su'.
  2. Step 2: Use the MySQL command-line tool to set a password for the root user using the following commands: `mysql -u root -p` (enter a temporary password), then `ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';`, and finally `FLUSH PRIVILEGES;`.
  3. Step 3: Exit the MySQL shell and exit the root user shell. Then, restart the MySQL service using the command 'sudo service mysql restart' or 'sudo systemctl restart mysql'.

💡 Conclusion

By following one of these methods, you should be able to resolve the error message 'Access denied for user 'root'@'localhost'(using password: YES)' and access your MySQL database without setting a password. Remember to replace any temporary passwords with secure ones in production environments.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions