MySQL出现 ERROR 1054 (42S22): Unknown column 'password' in 'field list' 错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ceovip/article/details/86186173

MySQL登陆成功之后,使用命令

update user set password=password("1234") where user="root";

修改密码的时候出现错误: ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’

D:\DevelopTools\mysql-5.7.10-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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 user set password=password("1234") where user="root";
ERROR 1054 (42S22): Unknown column 'password' in 'field list'

查了一下资料,发现MySQL5.7以后,password字段不再存在,变成了authentication_string,使用

update user set authentication_string=password("1234") where user="root";

命令重新修改就可以了。
修改完之后不要忘了使用flush privileges命令刷新MySQL权限。

mysql> update user set authentication_string=password("1234") 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什么时候需要flush privileges?
flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。

参考资料:
https://blog.csdn.net/u014756827/article/details/53164926

猜你喜欢

转载自blog.csdn.net/ceovip/article/details/86186173
今日推荐