MariaDB忘记root密码

来源:互联网 发布:淘宝店铺扣分24分 编辑:程序博客网 时间:2024/05/29 09:30

[root@localhost ~]# ll /etc/my.cnf
-rw-r--r--. 1 root root 570 Jun  8 22:25 /etc/my.cnf
[root@localhost ~]# chmod 744 /etc/my.cnf
[root@localhost ~]# ll /etc/my.cnf
-rwxr--r--. 1 root root 570 Jun  8 22:25 /etc/my.cnf

MariaDB配置文件/etc/my.cnf  [mysqld]中加入skip-grant-tables一行:

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables    #加入这一行
# Disabling symbolic-links is recommended to prevent assorted security risks

......

重启服务:

[root@localhost ~]# systemctl restart mariadb.service

进入MariaDB修改root密码:

[root@localhost ~]$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.56-MariaDB MariaDB Server


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


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

MariaDB [(none)]> update mysql.user set password=password('12345')where user='root' and host='localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 0


MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


MariaDB [(none)]> quit
Bye

[root@localhost ~]# systemctl restart mariadb.service

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.56-MariaDB MariaDB Server


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


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


MariaDB [(none)]> exit


[root@localhost ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#skip-grant-tables    #注释掉
# Disabling symbolic-links is recommended to prevent assorted security risks

......

[root@localhost ~]# chmod 644 /etc/my.cnf

[root@localhost ~]# ll /etc/my.cnf
-rw-r--r--. 1 root root 570 Jun  8 22:30 /etc/my.cnf
[root@localhost ~]#