1,停止mariadb服务
systemctl stop mariadb
2,修改配置文件 vim /etc/my.cnf 在[mysqld]下添加skip-grant-tables 意思是忽略密码, 保存并退出
3,启动Mariadb systemctl start mariadb
4,修改密码 mysql use mysql; UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; flush privileges ; quit
5,改回配置,重启服务 vim /etc/my.cnf 删除skip-grant-tables systemctl restart mariadb
6 ,进入数据库
mysql -uroot -p
输入新密码new-password即可
参考https://blog.csdn.net/linux_s2018/article/details/80762820