msyql修改密码-忘记密码

一、没有忘记密码

1)直接更改密码:mysqladmin -uroot -p’123’ password 'new_password’

[root@localhost ~]# mysqladmin -uroot -p'Jiaofan@123' password 'JiaoFan@1234'
[root@localhost ~]# mysql -uroot -p'JiaoFan@1234'

2)进入 msyql 更改密码:alter user ‘root’@‘localhost’ identified by ‘new_password’;

mysql> alter user 'root'@'localhost' identified by 'Jiao@1234';
mysql> flush privileges;

3)#创建新用户并产生随机密码

mysql> CREATE USER
       'u1'@'localhost' IDENTIFIED BY RANDOM PASSWORD,
       'u2'@'%.example.com' IDENTIFIED BY RANDOM PASSWORD,
       'u3'@'%.org' IDENTIFIED BY RANDOM PASSWORD;
+------+---------------+----------------------+
| user | host          | generated password   |
+------+---------------+----------------------+
| u1   | localhost     | BA;42VpXqQ@i+y{&TDFF |
| u2   | %.example.com | YX5>XRAJRP@>sn9azmD4 |
| u3   | %.org         | ;GfD44l,)C}PI/6)4TwZ |
+------+---------------+----------------------+

5)#修改随机密码

mysql> ALTER USER
       'u1'@'localhost' IDENTIFIED BY RANDOM PASSWORD,
       'u2'@'%.example.com' IDENTIFIED BY RANDOM PASSWORD;
+------+---------------+----------------------+
| user | host          | generated password   |
+------+---------------+----------------------+
| u1   | localhost     | yhXBrBp.;Y6abB)e_UWr |
| u2   | %.example.com | >M-vmjp9DTY6}hkp,RcC |
+------+---------------+----------------------+

6)修改随机密码

mysql> SET PASSWORD FOR 'u3'@'%.org' TO RANDOM;
+------+-------+----------------------+
| user | host  | generated password   |
+------+-------+----------------------+
| u3   | %.org | o(._oNn)d;FC<vJIDg9M |
+------+-------+----------------------+

7)其他有关密码管理请主动参考文档:
https://dev.mysql.com/doc/refman/8.0/en/password-management.html

二、忘记密码

1)更改配置文件,添加 skip-grant-tables 参数

[root@localhost ~]# vi /etc/my.cnf
[mysqld]
#在最后添加这个参数
skip-grant-tables

2)重启mysql

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -uroot -p
Enter password:         <==直接返回
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值