Centos7 of MariaDB (Mysql) solution root password forgotten

MariaDB (Mysql) root solution forgotten password

1. First, turn off the mariadb service database

# Close mariadb service commands (mysql if the command is to mariadb into mysql)

[root@node ~]# systemctl stop mariadb

# By tracking or by port access service also whether there

[root@node ~]# ps aux|grep mariadb

root       6852  0.0  0.0 112704   964 pts/2    S+   23:19   0:00 grep --color=auto mariadb

[root@node ~]# netstat -lntup|grep 3306

2. modify the configuration

Modify /etc/my.cnf file , the [mysqld] add the skip-grant-tables, then start mysql

# Open mariadb Service

[root@node ~]# systemctl start mariadb

# View service has been opened

[root@node ~]# ps aux|grep mariadb

mysql      7104  1.1  5.6 972516 80672 ?        Sl   23:22   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

root       7141  0.0  0.0 112704   964 pts/2    S+   23:22   0:00 grep --color=auto mariadb

# View port is also being used

[root@node ~]# netstat -lntup|grep 3306

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      7104/mysqld

3. To enter and update the database password

# Password-free accessible

root@node ~]# mysql -u root

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.60-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.

# Update password

MariaDB [(none)]> update mysql.user set Password=password('123') where User='root';

Query OK, 1 row affected (0.01 sec)

Rows matched: 4  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit;

Bye

4. Restore configuration requires a password

# Re-edit the original configuration and restart the service

[Root @ node ~] # vi /etc/my.cnf

[root@node ~]# systemctl restart mariadb

# Can see now can not enter without a password

[root@node ~]# mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

# Use the new password to enter mariadb database

[root@node ~]# mysql -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.60-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)]> 

This problem can be solved the same way other linux versions mariadb (mysql) Password Forgot problem

 

Guess you like

Origin www.cnblogs.com/hszstudypy/p/11518696.html