centos8 mariadb忘记root密码详细
在mariadb新版本中不能直接在my.cnf添加skip-grant-tables,会导致启动失败,貌似是密码策略的问题
下面是解决方法:
systemctl stop mariadb.service
mysqld_safe --skip-grant-tables &
执行后
mysqlroot@node1 ~]# mysqld_safe --skip-grant-tables &
[1] 2835
[root@node1 ~]# 210415 05:57:25 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
210415 05:57:25 mysqld_safe A mysqld process already exists
mysql #直接登录
use mysql
update user set password=password('admin') where user="root";#更改密码
(这条命令在mariadb新版本会报错)
update mysql.user set authentication_string=password('admin') where user='root';
(应该是mysql5.7以上就要换成authentication_string字段,日志报错是没有password字段)
flush privileges; #立即生效
quit退出
收尾
root@node1 ~]# mysqld_safe --skip-grant-tables &
[1] 2835
[root@node1 ~]# 210415 05:57:25 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
210415 05:57:25 mysqld_safe A mysqld process already exists
kill -9 2835
systemctl restart mariadb
最后杀死进程,重启后用新密码登录即可。