您的位置:首页 > 数据库 > MySQL

MySQL 8.0出现 Access denied for user 'root'@'localhost' ;忘记密码的解决方法;跳过权限检查

2019-03-24 23:57 1146 查看

1.管理员权限运行cmd

2.停止MySQL服务

命令行输入net stop mysql

3.跳过权限检查

现在mysqld -skip-grant-tables命令在8.0中没有用了!!!(我之前试了很多遍这个命令,包括在my.ini添加和在命令行中运行,试到崩溃……)

改为使用mysqld --console --skip-grant-tables --shared-memory

4.无密码登陆

另开一个管理员运行的cmd,使用mysql -u root -p命令,出现“enter password:”时直接按回车键,实现无密码登陆

5.改密码

mysql8.0之前更改root密码,输入update user set password=password('123456') where user='root' and host='localhost';因为mysql8.0之前密码字段是"password";

现在的字段是"authentication_string",所以改密码方式也有所变化

使用命令 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ‘你的密码’;

但是出现错误“The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement”,具体原因应该是–skip-grant-tables在命令行的时候,使得数据库只能是只读的权限。

使用命令:mysql> flush privileges;

再使用一次改密码命令即可

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐