mysql5.7修改密码最新版

2,710次阅读
没有评论

共计 632 个字符,预计需要花费 2 分钟才能阅读完成。

版本更新,现在网上的资料大部分都不能用了,博主写这个博客一开始就踩到坑了,现在把坑填了,博主的使用环境是阿里云ECS centos6.8+ mysqlsever5.7+mysql5.7

如果 mysql 正在运行,首先停止服务

service mysqld stop

修改/etc/my.cnf在[mysqld]之后加入

skip-grant-tables

 

重新进入mysql

mysql -u root -p

进入之后使用

use mysql;

下面看下数据库中的表

show mysql;

可以看到user表;

再详细看下user表

describe user;

现在你可以看到下图的信息

mysql5.7修改密码最新版

现在大部分代码都使用修改password字段,其实在5.7版本中早就取消了password字段了,现在的字段是authentication_string

所以更改代码的方式是:

mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';

mysql> flush privileges;

mysql> quit;

假设后期遇到了密码过期的问题使用以下代码解决

alter user 'root'@'localhost' identified with mysql_native_password as '你的密码
alter user 'root'@'localhost' password expire never;
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2017-04-30发表,共计632字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码