mariadb root用户忘记密码
1 root用户停止 mariadb 服务
[[email protected] ~]# systemctl stop mariadb.service
2 跳过授权表
[[email protected] ~]# mysqld_safe --skip-grant-table & # 跳过授权表
[1] 6201
3 直接输入mysql不用用户名和密码就可以进入mariadb了
[[email protected] ~]# mysql
4 更改root用户的密码为westos
MariaDB [(none)]> update mysql.user set Password=password('westos') where User='root';
5 杀死mysqld_safe --skip-grant-table进程
[[email protected] ~]# 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
[[email protected] ~]# kill -9 6260
[[email protected] ~]# 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服务
[[email protected] ~]# systemctl start mariadb.service
7用更改过的密码就可以重新登陆
直接输入 mysql已经不能直接进入了
[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[[email protected] ~]# mysql -uroot -pwestos