小韩实操 -- Mysql密码忘记之后如何修改

环境:

centos 7.5             mysql版本  5.5

1)下载数据库

[root@hya ~]# yum -y install mariadb mariadb-server
[root@hya ~]# rpm -qa mariadb-*
mariadb-libs-5.5.65-1.el7.x86_64
mariadb-server-5.5.65-1.el7.x86_64

2)启动数据库并设置密码

[root@hya ~]# systemctl  start mariadb
[root@hya ~]# ss -tnl
State       Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN      0      50                       *:3306                                 *:* 
[root@hya ~]# mysqladmin -uroot password 'hya123';
或者也可以
##################################################
mysql> use  mysql;
mysql> update user set password=PASSWORD('hya123') where user='root';
mysql> flush privileges;
##################################################
正常情况下(知道密码)修改密码
mysqladmin  -uroot  -phya password ‘新密码’;

3)模拟忘记密码后的恢复

###首先关闭mysql
[root@hya ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@hya ~]# systemctl  restart mariadb
[root@hya ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set password=PASSWORD('xiaohan123') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0      ###修改成功
###5.7版本不同,为以下命令
mysql> update mysql.user set authentication_string = password("xiaohan123") where user="root" and host="localhost";
####
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye
###然后进my.cnf删除刚才添加的那一条跳过所有错误的代码
[root@hya ~]# vim /etc/my.cnf
skip-grant-tables  删除
[root@hya ~]# systemctl  restart mariadb   密码修改完成后记得重启mysql
或者###############################################################
cd /usr/local/mysql/bin
./mysqld_safe  --user=mysql --skip-grant-tables --skip-networking &
###################################################################

4)测试

[root@hya ~]# mysql -uroot -pxiaohan123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
###可以了

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

胖胖不胖、

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

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

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

打赏作者

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

抵扣说明:

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

余额充值