mysql更改密码

mysql更改密码

进入到MySQL输入以下指令

mysql更改密码
进入到MySQL输入以下指令



mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> update user set plugin="mysql_native_password"; 
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4  Changed: 0  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.12 sec)

ALTER USER “root”@“localhost” IDENTIFIED WITH mysql_native_password BY “your password”;


退出重新进入即可。.
show databases;  #查看数据库
use mysql;       #使用数据库

        

update user set authentication_string=PASSWORD("123456") where user='root';  

#修改密码,密码设置的是 123456



update user set plugin="mysql_native_password";

flush privileges; #刷新

exit;  #退出,密码已经修改成功

/etc/init.d/mysql restart   #重启mysql

重置为新的密码,这里分为两个版本

一直使用5.7的命令在8.0的版本中执行,一直报错,感到很诧异,后查找资料后发现,mysql 5.7.9以后废弃了password字段和password()函数;

而且用于表示用户密码的authentication_string字段只能是mysql加密后的41位字符串密码。因此在修改密码时,5.7版本和8.0版本有所不同,需要使用不同的语句执行,其他版本也有可能不同。

1、MySql5.7

update user set authentication_string = password(["your new password"]) where user = "your username" [and Host="localhost"];

2、MySql8.0

(1)检查authentication_string字段是否为空,不为空先置空,我比较懒,我就直接置空了。

use mysql;
update user set authentication_string='' where user='root';
ALTER user 'root'@'localhost' IDENTIFIED BY '123456';

(2)如果顺利执行,那么恭喜你已经修改密码成功了,如果报错则执行flush privileges;刷新MySQL的系统权限相关表后再次执行上一步。


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰诺飞雪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值