myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

凤凰 2021-5-11 163 5/11

mysql忘记密码的解决办法:首先找到“my.ini”文件;然后在“mysqld”下加上“skip-grant-tables”;接着重启mysql服务;最后通过update重新设置密码即可。

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

本文操作环境:Windows7系统、Dell G3电脑、MySQL Server 5.7。

mysql忘记密码怎么办?

我们在安装使用MySQl 时,有时可能避免不了忘记密码,如果你忘记密码,可以按照如下方案进行操作:

  • 找到my.ini 文件
    my.ini 文件为 MySQl 设置文件, 如果你是默认的安装地址,文件在
    C:\ProgramData\MySQL\MySQL Server 5.7 下
    但是ProgramData 常规状态下是隐藏的

  • 设置权限认证跳过
    也就是在 [mysqld] 下 加上 skip-grant-tables

   skip-grant-tables

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

重启 mysql 服务

这里可以直接在命令行中连续输入 或者在服务里找到mysql 服务重启

 	net stop mysql
 	net start mysql

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

重启后, 以 mysql -uroot -p 登陆
会发现我们可以不需要密码就可以登陆

    mysql -uroot -p

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

  • 重新设置密码

首先先选择 mysql 数据库

   use mysql

然后更新 password

   update user set authentication_string = password ( 'new-password' ) where user = 'root' ;

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程
注:这里要更改的是 authentication_string, 而不是password 字段
输入

   update user  set Password=password('new-password') where user='root'

会报错: ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’;
myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

原因是 mysql 数据库下已经没有password 字段了,password 字段改成了 authentication_string

  • 在 my.ini 文件中去掉 加上的 skip-grant-tables

  • 重启 mysql 服务

  • 以新密码登陆

myMySQL数据库忘记密码了怎么解决 MySQL数据库使用教程

推荐学习:《mysql视频教程》

以上就是mysql忘记密码了怎么解决的详细内容,更多请关注本站其它相关文章!

声明:本文原创发布本站,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

- THE END -
Tag:

凤凰

5月11日09:10

最后修改:2021年5月11日
0

非特殊说明,本博所有文章均为博主原创。