mariadb 5.5 root密码忘记改密

本篇用于解决mariadb5.5 root密码忘记改密的问题(系统版本centos7.6)
step1:
关闭mariadb服务:

[root@kerberos ~]# systemctl stop mariadb

step2:
关闭密码验证:
1.

[root@kerberos ~]# mysqld_safe --skip-grant-tables &   (切记一定要输“&”否则会造成当前终端一直无响应,ssh或者图形界面可以直接关闭当前会话,命令行界面就只能重启了,楼主手贱重启了好几次)

2.也可以在/etc/my.cnf 里,mysqld字段内加入“skip-grant-tables”,然后重启mariadb
step3:
登陆mariadb:

[root@kerberos ~]# mysql -u root -p
Enter password:            (回车即可)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

step4:
改密:

MariaDB [(none)]> update mysql.user set password=password('root') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)                  (其他改密语句试了均不行,要么改不了,要么改了登陆不了)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@kerberos ~]# mysql -uroot -proot       (输入刚才输入的密码即可登陆)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

step5:
关闭刚刚启动的mysqld进程:

[root@kerberos ~]# killall mysqld

step6:
重启并验证登陆mariadb:

[root@kerberos ~]# systemctl restart mariadb
[1]+  Done                    mysqld_safe --skip-grant-tables
[root@kerberos ~]# mysql -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

本文借鉴此处blog,并在其基础上作了少许完善:
https://www.linuxidc.com/Linux/2019-08/160126.htm

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值