1.暂停mariadb服务
systemctl stop mariadb
2.修改配置文件
vi /etc/my.cnf
在[mysqld]下边添加skip-grant-tables保存退出
3.重启mariadb服务
systemctl restart mariadb
4.进入数据库,修改密码
mysql
>update mysql.user set password=password('密码') where user='root';
或者>update mysql.user set authentication_string=password('111111') where user='root';
>flush privileges;
>quit
5.关闭mariadb服务
systemctl stop mariadb
6.更改之前修改的配置文件
#skip-grant-tables去掉此行,保存退出
7.通过之前的密码进入到数据库
msyql -p密码