1.修改配置文件
#vim /etc/my.cnf
[mysqld]
skip-grant-table //添加 跳过权限表
datadir=/var/lib/mysql

2.重启服务
# systemctl restart mariadb.service

3.登陆mysql
# mysql
MariaDB [(none)]> select user,password,host from mysql.user; //查看mysql库中user表的user、password、host三个字段
+------+-------------------------------------------+-----------------+
| user | password | host |
+------+-------------------------------------------+-----------------+
| root | *23AE809DDACAF96A | localhost |
| root | | ula.example.com |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | ula.example.com |
+------+-------------------------------------------+--------------------+

MariaDB [(none)]> update mysql.user set password=password("123") where user="root" and host="localhost"; //更新密码
MariaDB [(none)]> exit
Bye

4.将配置文件中跳过权限表的选项删除或注释
#vim /etc/my.cnf
[mysqld]
#skip-grant-table
datadir=/var/lib/mysql

5.重启服务
# systemctl restart mariadb.service 

03-17 04:18