Can't set root MySQL password to null

余生长醉 提交于 2019-12-12 04:37:37

问题


When installing mysql, I didn't put anything in the root password fields, but when I ran mysql -u root I still got Access denied for user 'root'@'localhost'.

I started mysql up in safe mode without the grant tables, sudo mysql_safe --skip-grant-tables &, then jumped in with mysql -u root without a problem.

Then I did use mysql; update user set authentication_string=null where user='root'; and I got:

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

Anyone have any insight on why the password isn't updating?


回答1:


You forgot

FLUSH PRIVILEGES;

Step by step it will be like this

Stop the MySQL Server.

sudo /etc/init.d/mysql stop

Start the mysqld configuration.

sudo mysqld --skip-grant-tables &

Login to MySQL as root.

mysql -u root mysql

Replace YOURNEWPASSWORD with your new password!

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;



回答2:


I had to set the plugin to mysql_native_password, so the password reset part looks like this:

update user set authentication_string=password(''), plugin='mysql_native_password' where user='root'; FLUSH PRIVILEGES;


来源:https://stackoverflow.com/questions/39813080/cant-set-root-mysql-password-to-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!