简体   繁体   中英

Can't run mysql commands as root linux user

As linux root user:

root@local:~# mysql

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

I'm confused. Shouldn't the root user be able to run mysql without additional authentication? How do I fix this?

If the MySQL root user has a password, using the default authentication plugin, then you must provide a password to connect, full stop. You can configure an account with no password, but that's a habit you should avoid.

You can provide a password by any of the following means:

There's also a way to provide a password through environment variables, but that's discouraged now because it's really not secure.

Your root account in MySql has a password. Try this

mysql -p

and enter the password you, or somebody set.

If that doesn't work try

mysql -h localhost -u root -p

It that doesn't work you'll need to reset your MySql root password. That's the topic of several tutorials on the 'toobz

I had same issue. This is what I do.

  1. Login with:
root@local:~# sudo mysql
  1. Change password with:
mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
mysql > FLUSH PRIVILEGES;
  1. Then try login with:
root@local:~# mysql

My problem solved.

ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;

Thanks to everyone who didn't understand the question or was too arrogant to believe there was a solution they weren't aware of and downvoted the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM