Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

how to login mysql shell when mysql have no password

Writer Matthew Barrera

I got this error:

root@sys3026:/home/sys3026# mysql --user=root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Any one please help me. Thanks in advance..

6 Answers

When a MySQL user is configured to use auth_socket (instead of mysql_native_password), as it is by default in Ubuntu 18.04, you can log-in as root (for example) in the following way:

sudo mysql -u'root'

or just:

sudo mysql

References:

If your database has no password, just leave out the --password parameter.

$ mysql --user=root

Reference:

If you have forgotten your password or you can not login you can always run mysql in a "safe_mode". Which allows you to access it without any password restriction - to change the root password or adjust something else if something went wrong.

systemctl stop mysql
sudo mysqld_safe --skip-grant-tables &

Now you can access the mysql server without a password.

mysql -uroot

Add a new password to the root user in the mysql shell

use mysql;
update user set password=PASSWORD("newpassword") where User='root';
flush privileges;

Now restart it in normal mode again and it will work with the new password.

systemctl stop mysql
systemctl start mysql

Try this.

This is the command to run mysql when no password is set, But If you just installed it and you did not set any password, I am pretty sure it still has a random password that can be found in logs located in /var/log/mysql.

mysql -u root

sudo mysql -e "CREATE USER $USER" to do further logins without sudo

You can also create a user for yourself without setting a password:

sudo mysql -e "CREATE USER $USER"

and from now on you can login directly with:

mysql

This works based on the same principle as why sudo mysql works for root as mentioned at : if the password is not set, it seems to automatically try and authenticate by Linux username.

Tested on Ubuntu 20.10.

Make sure to check this step by step tutorial as well. It offers some more insights that the official guide does not. I hope it helps.

Reference:

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy