本篇用于解决mariadb5.5 root密码忘记改密的问题(系统版本centos7.6)
step1:
关闭mariadb服务:
[root@kerberos ~]# systemctl stop mariadb
step2:
关闭密码验证:
1.
[root@kerberos ~]# mysqld_safe --skip-grant-tables & (切记一定要输“&”否则会造成当前终端一直无响应,ssh或者图形界面可以直接关闭当前会话,命令行界面就只能重启了,楼主手贱重启了好几次)
2.也可以在/etc/my.cnf 里,mysqld字段内加入“skip-grant-tables”,然后重启mariadb
step3:
登陆mariadb:
[root@kerberos ~]# mysql -u root -p
Enter password: (回车即可)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.64-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)]>
step4:
改密:
MariaDB [(none)]> update mysql.user set password=password('root') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec) (其他改密语句试了均不行,要么改不了,要么改了登陆不了)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@kerberos ~]# mysql -uroot -proot (输入刚才输入的密码即可登陆)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-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)]>
step5:
关闭刚刚启动的mysqld进程:
[root@kerberos ~]# killall mysqld
step6:
重启并验证登陆mariadb:
[root@kerberos ~]# systemctl restart mariadb
[1]+ Done mysqld_safe --skip-grant-tables
[root@kerberos ~]# mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-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)]>
本文借鉴此处blog,并在其基础上作了少许完善:
https://www.linuxidc.com/Linux/2019-08/160126.htm