mysql 解决忘记密码

51 篇文章 0 订阅
5 篇文章 0 订阅

首先,打开mysql的配置文件:/etc/my.cnf

在这里插入图片描述
在 [mysqld] 下面添加 skip-grant-tables;然后 :wq 保存退出

连接mysql服务,再更改密码


[root@localhost mysql]# mysql -uroot

# 刷新mysql
mysql> flush privileges;

# 修改密码
mysql> alter user "root"@"localhost" identified by "root";

# 刷新mysql
mysql> flush privileges;

如果,报错:

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

是因为加了免密码权限造成的,那如何解决;往下看:


我们新建一个用户,记住其密码


#首先连接mysql
[root@localhost ~]# mysql -uroot

#进入 mysql 库
mysql> use mysql;

# 刷新mysql
mysql> flush privileges;

#新建一个用户 ( starsky 是新用户名 123456 是密码 )
mysql> create user `starsky`@`%` identified by '123456';

#给予权限
mysql> grant all on *.* to `starsky`@`%` with grant option;

# 再给一个客户端连接mysql权限
mysql> alter user 'starsky'@'%' identified with mysql_native_password by '123456';

# 退出
mysql> quit

#连接mysql
[root@localhost ~]# mysql -ustarsky -p123456

# 刷新mysql
mysql> flush privileges;

# 再修改密码
mysql> alter user "root"@"localhost" identified by "root";

如果到这里,还继续报错:

ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

ERROR 1396 (HY000): Operation ALTER USER failed for ‘root’@‘localhost’


那最后的解决办法就是使用 Navicat 连接mysql,把新建的mysql 用户 starsky 的密码赋予给root

首先,把 mysql 配置文件的 skip-grant-tables 去掉,然后重启 MySQL 服务。
在这里插入图片描述
Navicat 连接MySQL报错解决:

1130-host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server
https://blog.csdn.net/qq_39408664/article/details/119346632

2003 - Can‘t connect to MYSQL server on ‘xxx.xxx.xxx.xxx‘ ( 10038 )
https://blog.csdn.net/qq_39408664/article/details/118707777

1251 -Client does not support authentication protocol requested by server consider upgrading MYSQL client
https://blog.csdn.net/qq_39408664/article/details/118728976

按照上面方法替换 root 密码,然后重启 MySQL 服务,即可连接。

在这里插入图片描述




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值