I'm trying to login into fresh install mysql with:

sudo /usr/local/mysql/bin/mysql -u root

But getting following error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

The mysql server started with:

sudo /usr/local/mysql/bin/mysqld --user=root

What is the default login/password for mysql root user?

Thank you.


4 Answers 4


You can reinit the password :

1.stop mysql

/etc/init.d/mysql stop

2.start mysql safe :

mysqld_safe --skip-grant-tables &

3.connect to mysql

mysql -u root

4.change the password

mysql> use mysql;
mysql> update user set password=PASSWORD(”YOUR_PASSWORD”) where user=’root’;
mysql> flush privileges;
mysql> quit

5.stop mysql

/etc/init.d/mysql stop

6.start mysql

/etc/init.d/mysql start

Then you can connect to mysql with login root and the new password.

  • Trying to use mysqld_safe resulted in SOCKET file errors. I was able to fix these by manually making the directory and then giving it to the mysql user. See this answer. (Mint 18, mysql 5.7) Sep 20, 2017 at 10:33
  • What is "mysqld_safe" and where am I supposed to search for one? Apr 20, 2020 at 13:20

There is a subtle issue that needs stating:

sudo /usr/local/mysql/bin/mysql -u root
sudo /usr/local/mysql/bin/mysql -u root -p

The first case tries to log in without a password.
The second case will prompt you for a password. At that point you will get a different error message if you don't provide the correct password:

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

Installing MySQL manually by downloading packages for the first time generates a default password for root. Copy and save that. If not done somehow on successive re-installations it does not show that password.

Thus you cannot login to root. Do the following :

  1. Find mysql related entries from system sudo find / -name mysql
  2. Remove all mysql related entries by doing rm -rf <mysql_entries_above>
  3. Download latest mysql-server and intall it.
  4. You will be promted with a default password which you need to copy.
  5. Run mysql_secure_installation and paste that password when asked for root.
  6. Subsequently follow the steps and change admin password when prompted for.

In the recent version of MySQL running on Ubuntu 18.04, step as below:

  1. Find the .conf file, in my case it locate at


  1. Add under [mysqld]


  1. Restart the service

sudo service mysql restart

  1. Connect to mysql

mysql -u root

  1. Change the password

mysql> use mysql; mysql> update user set authentication_string=PASSWORD('YOUR_PASSWORD') where user='root'; mysql> flush privileges; mysql> exit;

  1. Restart mysql again

sudo service mysql restart

Voila, you can connect now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.