1 root用户停止 mariadb 服务
[root@foundation65 ~]# systemctl stop mariadb.service
2 跳过授权表
[root@foundation65 ~]# mysqld_safe --skip-grant-table & # 跳过授权表
[1] 6201
3 直接输入mysql不用用户名和密码就可以进入mariadb了
[root@foundation65 ~]# mysql
4 更改root用户的密码为westos
MariaDB [(none)]> update mysql.user set Password=password('westos') where User='root';
5 杀死mysqld_safe --skip-grant-table进程
[root@foundation65 ~]# ps aux | grep mysql
root 6260 0.0 0.0 113252 1576 pts/1 T 17:17 0:00 /bin/sh /bin/mysqld_safe --skip-grant-table
mysql 6403 0.0 0.0 0 0 pts/1 Z 17:17 0:00 [mysqld] <defunct>
root 6532 0.0 0.0 112648 960 pts/1 S+ 17:20 0:00 grep --color=auto mysql
[root@foundation65 ~]# kill -9 6260
[root@foundation65 ~]# ps aux | grep mysql
root 6534 0.0 0.0 112648 960 pts/1 S+ 17:21 0:00 grep --color=auto mysql
6重新开启mariadb服务
[root@foundation65 ~]# systemctl start mariadb.service
7用更改过的密码就可以重新登陆
直接输入 mysql已经不能直接进入了
[root@foundation65 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@foundation65 ~]# mysql -uroot -pwestos