1-mariadb - 用户管理

centos7中mariadb的密码找回

centos7 + mariadb5.5.68

流程:

[root@VM-8-17-centos ~]# systemctl stop mariadb
[root@VM-8-17-centos ~]# mysqld_safe --skip-grant-tables --skip-networking &
[root@VM-8-17-centos ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> -- 1. 加载授权按表
MariaDB [(none)]> flush privileges;

MariaDB [(none)]> -- 2. 更新root账号的密码
MariaDB [mysql]> update mysql.user set password=password("123") where user="root";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> -- 3. update之后一定要flush privileges; 否则生效
MariaDB [mysql]> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> -- 4. 到这一步基本上就搞定了。
MariaDB [mysql]> exit;
Bye
[root@VM-8-17-centos ~]# 5. 杀掉MySQL服务器
[root@VM-8-17-centos ~]# pkill mysql
[root@VM-8-17-centos ~]# 6. 重启MySQL服务器
[root@VM-8-17-centos ~]# systemctl start mariadb
[root@VM-8-17-centos ~]# 7. 现在就可以正常的登录了
[root@VM-8-17-centos ~]# mysql -uroot -p123
[root@VM-8-17-centos ~]# mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
posted @ 2023-09-17 20:38  听雨危楼  阅读(15)  评论(0编辑  收藏  举报