MySQL 修改密码

方法一

1: 通过任务管理器或者服务管理,关掉mysqld(服务进程) 
2: 通过命令行+特殊参数开启mysqld mysqld --defaults-file="D:\ProgramFiles\mysql\MySQLServer5.7Data\my.ini" --skip-grant-tables 3: 此时,mysqld服务进程已经打开。并且不需要权限检查
4: mysql -uroot 无密码登陆服务器。另启动一个客户端进行
5: 修改权限表 (1) use mysql; (2)update user set authentication_string=password('新密码') where user='root' and Host='localhost'; (3)flush privileges;
6: 通过任务管理器,关掉mysqld服务进程。

7: 再次通过服务管理,打开mysql服务。
8: 即可用修改后的新密码登陆

 

方法二

1、修改mysql配置,并重启:
在my.cnf 文件中添加skip-grant-tables
重启mysql:systemctl restart mysqld
2、直接mysql 登录,此时不需要填写密码。
3、清空root用户密码:
update mysql.user set authentication_string='' where user='root';
4、修改mysql配置,并重启:
在my.cnf 文件中注释掉skip-grant-tables,重启mysql:systemctl restart mysqld;
5、mysql -uroot 无密码登录到root模式。
6、查看root用户:
select user,host from user where user='root';
7、更新root密码:
alter user 'root'@'localhost' identified by 'new_password';
8、刷新权限:
flush privileges;

原文链接:https://blog.csdn.net/huryer/article/details/106957990

 

posted @ 2021-06-16 19:49  10132714  阅读(136)  评论(0编辑  收藏  举报