1

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..

2

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:

1

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

$ mysql --user=root

Reference:

0

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

0

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
0

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 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.

0

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: https://scalegrid.io/blog/how-to-set-up-mysql-digitalocean/

1
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
    – Community Bot
    Sep 6 at 21:12

Your Answer

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

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