MySQL重置密码

MySQL重置密码

1.打开一个dos窗口 停止MySQL服务

net stop mysql

2.无密码启动

mysql --console --skip-grant-tables --shared-memory

3.重新开一个dos窗口,无密码登录进入,清空密码

mysql -u root
update mysql.user set authentication_string='' where user='root' and host='localhost';

4.退出开启的两个dos窗口,重新再打开一个 重启MySQL

mysql start mysql

5.再次无密码登录进去 重新设置密码

mysql -u root
切换到MySQL库
use mysql;
设置密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
刷新权限
FLUSH PRIVILEGES;
退出
quit;

现在就密码重置好了!

对于MySQL5.7的版本,因为在user表中没有password字段,所以一直使用如下代码,来修改root密码

use mysql; 
update user set authentication_string = password(“root”) where user = “root”;

查阅后知道在mysql5.7.9以后废弃了password字段和password函数;authentication_string:字段表示用户密码。

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;

出现以上问题需要执行

刷新权限
flush privileges
  • 11
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值