mysql学习笔记1:忘记密码

我使用的mysql版本为:5.6.50,操作系统为:win10

一、修改配置文件my.ini 

1、在C:\ProgramData\MySQL\MySQL Server 5.6文件夹下找到my.ini配置文件

2、设置权限认证跳过

 找到[mysqld],在下面这行代码的下面加上 skip-grant-tables

 二、重启mysql服务

可以直接在命令行中输入命令重启,或者在进程中找到mysql的服务关闭再重启

#关闭

net stop mysql

#重启

net start mysql

 

三、以无密码的状态登录

mysql -uroot -p

 四、重新设置密码

1、选择 mysql 数据库

use mysql

2、更新 password

我操作的版本用下面的命令:

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

有一些低版本的,或者其他版本的用的是authentication_string字段,(本人未遇到,听说的)

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

五、复原配置文件的修改

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

六、重启mysql服务,并以新的密码登录即可

猜你喜欢

转载自blog.csdn.net/wanggmm/article/details/128095428