mysql8.0.12忘记密码的处理方法

本人没有保管号自己mysql的密码,致使无法登陆上,搜寻了一下午,一无所获,后来在一片博客中发现网上的都是8.0以前的版本所以不能使用与自己的8.0版本,安装博主的步骤自己试了试,可以运行。

希望能够帮助自己和朋友们少走弯路

0.修改my.ini 文件在【mysqld】段下面加入skip-grant-tables,并关闭mysql服务

1.使用cd指令切换到mysql的bin目录

2.使用mysqld --defaults-file=" my.ini配置文件的路径" -console -skip-grant-tables这时系统如下图。之后的步骤与8.0之前的版本完全相同。但是为了加强记忆我在写一遍。

 3.再打开一个命令行,转到mysqlbin目录下输入mysql

4.使用show database查看所有数据库

5.使用 use 【数据库名】指令打开指定的数据库,这是系统回复 database changed

6.这是可以使用指令select user,host,authentication_string from user 观看数据库密码

 

 7.输入flush privileges否则会出现错误

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

 

8. 使用ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';修改密码,注意新密码的格式为  大写字母+小写字母+特殊符号+数字否则密码不生效

有些博客采用update user set authentication_string='12345' where user='root' ;来修改密码,我试过,没用。当然有的博客上说如果authentication_string下有值则需用

update user set authentication_string='' where user='root' ;先清除一下authentication_string。这个我还没有测试。

注意密码字段在数据库中的名字为authentication_string不是password另外语句最后的分号不能,而且password()函数再高版本也不能用了。

9.最后可以使用quit离开数据库

如果出现了数据库显示正在运行,这个不用管,这是my.ini加入skip-grant-tables的原因造成的

如果提示无法打开数据库那么可以先删除mysql安装目录下的data文件夹,然后在cmd下重新初始化数据库

 

posted @ 2018-10-07 20:06  飞扬吧青春  阅读(26453)  评论(0编辑  收藏  举报