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..
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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'
If your database has no password, just leave out the
$ mysql --user=root
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.
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
sudo mysql -e "CREATE USER $USER" to do further logins without
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:
This works based on the same principle as why
sudo mysql works for
root as mentioned at https://askubuntu.com/a/1129495/52975: 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.