Mysql password recovery management

MySQL database password recovery principle steps

  • Stop Mysql service program

  • Skip Authorization Form to start MySQL service program

  • Reset root password (user table update records)

  • In the normal way to restart the MySQL service program


Examples of password recovery

Example 1: Reset MySQL password management

  • First, stop the MySQL service program has been running

[root@host50 ~]# systemctl stop mysqld
[root@host50 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2019-07-02 03:54:56 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1426 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1083 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1430 (code=exited, status=0/SUCCESS)

Jul 02 03:31:22 host50 systemd[1]: Starting MySQL Server...
Jul 02 03:31:36 host50 systemd[1]: Started MySQL Server.
Jul 02 03:54:55 host50 systemd[1]: Stopping MySQL Server...
Jul 02 03:54:56 host50 systemd[1]: Stopped MySQL Server.
  • Skip Authorization Form to start MySQL service program (configuration --skip-grant-tables option) See the last line of the document

[root@host50 ~]# vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure_file_priv="/myload"
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-storage-engine=innodb
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip_grant_tables=1
  • After reconnection mysql mysql database by modifying the user records in the table, so that the machine user to reset root password

[root@host50 ~]# systemctl restart mysqld
[root@host50 ~]# mysql -uroot
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('123456')
-> WHERE user='root' AND host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges; 
Query OK, 0 rows affected (0.01 sec)
mysql> exit

Note: By executing "FLUSH PRIVILEGES;" authorization form allows immediate effect, for the normal operation of MySQL service, you can also use the above method to modify the password, do not restart the service. Since the present embodiment is the recovery password, preferably restart the MySQL service program, so the above-described "FLUSH PRIVILEGES;" operation may be skipped.

  • Mysql restart the service program in the normal way to verify a new password (may comment skip_grant_tables option)

[root@host50 ~]# vim /etc/my.cnf
[mysqld]
#skip_grant_tables=1
.
.
.
[root@host50 ~]# systemctl restart mysqld
[root@host50 ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@host50 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>


Example 2: Reset Mysql Manager user password (password known)

  • Method One: Use mysqladmin management tools need to verify old password

[root@host50 ~]# mysqladmin -u root -p password 'qaz123edc'                    
Enter password:                                   
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
  • Method II: Log mysql to root, using the instruction set password settings (configuration must first validate_password_policy = 0)

mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • Act III: mysql login to root, use grant authorization tool set

mysql> grant all on *.* to root@localhost identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • Act Four: After logging in to the MySQL root, use update update the corresponding table records

mysql> update mysql.user set authentication_string=password('123456')
    -> where user='root' and host='localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1












Guess you like

Origin blog.51cto.com/11483827/2416005