5.7版本
1、管理员权限登陆cmd,不会使用管理员登陆的请搜索cmd,搜索结果右键。
2、命令行输入:net stop mysql;然后提示。服务停止中 --> 服务已停止。
打开服务 win+R --> services.msc --> 回车,找到mysql开头的服务名。
在服务中查看服务具体名称,比如mysql57。
这里停掉服务再执行这一行
3、由于mysqld –skip-grant-tables实测在mysql8.0中已失效,现使用mysqld --console --skip-grant-tables --shared-memory
4、另外开一个cmd,使用mysql直接无密登录。
5、执行如下命令
mysql> update user set password=password(“新密码”) where user=”用户名”;
执行后报错 ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’
错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
mysql> update user set password=password(“123456”) where user=“root”; #修改密码报错
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
mysql> update mysql.user set authentication_string=password(‘123456’) where user=‘root’; #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1