MySQL5.7和之前的用户修改密码方式:mysql -uroot -e "Set password=password(‘123’);"
mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456') where user='root';"
update mysql.user set authentication_string=password("123") where user='root';
以上三种方法在MySQL8.0以后版本中将不能使用,如果使用了将会导致在正确修改密码是报如下错误:mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
如遇上以上问题请使用update语句先清空authentication_string字段,然后再修改密码即可update user set authentication_string='' where user='root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
所以特别提醒童鞋们:
MySQL8.0后请使用alter修改用户密码
|