1、如果不为空
use mysql;
update user set authentication_string='' where user='root'; --将字段置为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root'; --修改密码为root
2、如果为空,直接修改
ALTER user 'root'@'localhost' IDENTIFIED BY 'root'; --修改密码为root
如果出现如下错误
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
需要执行
flush privileges;
然后再执行
ALTER user 'root'@'localhost' IDENTIFIED BY 'root'; --修改密码为root