1、找到mariadb配置文件
命令:find / -name my.cnf
备注:一般是在 /etc/my.cnf
2、修改配置文件
在MariaDB配置文件/etc/my.cnf的[mysqld]配置中加入一行:skip-grant-tables
#=======================================================
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables #注意:插入的就是这行
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
skip-grant-tables
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#=======================================================
3、通过SQL修改root密码
[Richard@localhost ~]$ mysql
MariaDB [mysql]> UPDATE user SET Password = password ( '123456 ) WHERE User = 'root' ;
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [mysql]> exit
4、完成,取消免密登录,重启mariadb
5、附上mariadb相关命令
查询状态:systemctl status mariadb
关闭:systemctl status mariadb
开启:systemctl stop mariadb
重启:systemctl restart mariadb