Linux MariaDB 遗忘密码后重置密码
MariaDB 是 MySQL 的一个分支数据库。处理的办法和 MySQL 相同。
修改 MySQL 配置文件
在 [mysqld] 追加配置项:
[root@node9 ~]# vim /etc/my.cnf
[root@node9 ~]# cat /etc/my.cnf
...
[mysqld]
skip-grant-tables
...
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
重启相关服务
该示例使用的是 MariaDB,重启该服务并查看是否启动成功:
[root@node9 ~]# systemctl restart mariadb
[root@node9 ~]# systemctl status mariadb
- 1
- 2
- 1
- 2
登陆数据库修改密码
[root@node9 ~]# mysql -uroot -p
MariaDB [mysql]> UPDATE user SET Password = password('48eb1c1c770d4bbc') WHERE User = 'root' ;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
这边需要注意 password 必须需要写进来,否则修改不完全,报错信息如下:
[root@node9 ~]# mysql -uroot -p
MariaDB [mysql]> UPDATE user SET Password = '48eb1c1c770d4bbc' WHERE User = 'root' ;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
...
[root@node9 ~]# mysql -uroot -p
Enter password:
ERROR 1275 (HY000): Server is running in --secure-auth mode, but 'root'@'localhost' has a password in the old format; please change the password to the new format
...