MySQL 5.7.21更改root用户密码
发布于 2018年03月29日
· 最近修改于 2026年03月23日

今天将小站上面的
MySQL版本升级到了最新的5.7.21,然后在更改root用户密码的时候遇到了问题,mysql环境下使用的更改root密码的语句为:
[code]update user set password=password("********") where user='root';[/code]
回车然后报错内容如下:
[code]ERROR 1054 (42S22): Unknown column 'password' in 'field list'[/code]
于是我查询资料,得出错误的原因是5.7以后的版本中mysql数据库下已经没有password这个字段了,password字段改成了authentication_string,于是按照下面的代码尝试了一下:
[code]>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: ******** #输入新密码[/code]
新密码登陆成功 -_<
评论 (0)
请 登录 后发表评论,或填写以下信息:
暂无评论,快来发表第一条评论吧!