进无止境

MySQL 5.7.21更改root用户密码


今天将小站上面的MySQL版本升级到了最新的5.7.21,然后在更改root用户密码的时候遇到了问题,mysql环境下使用的更改root密码的语句为:

update user set password=password("********") where user='root';

回车然后报错内容如下:

ERROR 1054 (42S22): Unknown column 'password' in 'field list'

于是我查询资料,得出错误的原因是5.7以后的版本中mysql数据库下已经没有password这个字段了,password字段改成了authentication_string,于是按照下面的代码尝试了一下:

>mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 102
Server version: 5.7.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql> update mysql.user set authentication_string=password('********') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
>mysql -u root -p
Enter password: ******** #输入新密码

新密码登陆成功 -_<

发表评论

您的电子邮箱地址不会被公开。