Forgot your password or mariadb the mysql database solutions

First, the experimental environment

CentOS Linux release 7.5.1804 (Core)

mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

Second, embodiments

The first step: Adding --skip-grant-tables

In /etc/my.cnf.d/server.cnf the [mysqld] add the following options

[mysqld]
skip-grant-tables

 

Step two: Restart the database

[root@ken ~]# systemctl restart mariadb

 

The third step: Log Database

Now found directly log into the database without entering a password

Copy the code
[root@ken ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
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)]> 
Copy the code

 

Step four: Change Password

This time using the grant to change the password will be reported the following error

MariaDB [(none)]> grant all on *.* to root@'localhost' identified by '123'; ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

 

Use set to change the password will be reported the same mistakes

MariaDB [(none)]> set password for root@localhost=password('123'); ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

 

Now you can use update to modify

MariaDB [(none)]> use mysql;   #切换至mysql数据库
Database changed

MariaDB [mysql]> update user set password=password('123') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 4 Changed: 3 Warnings: 0

 

Step Five: configuration file options written off

[root@ken ~]# vim /etc/my.cnf.d/server.cnf
...
[mysqld]
#skip-grant-tables

 

Step six: Restart the database

[root@ken ~]# systemctl restart mariadb

 

Step Seven: Once again authenticates

Now do not enter a password directly rejected

[root@ken ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

 

Enter the password to log 123

Copy the code
[root@ken ~]# mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
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)]> 
Copy the code

Guess you like

Origin www.cnblogs.com/daisyyang/p/11068004.html