Take MySQL multi-instance as an example to demonstrate the password to retrieve MySQL root
1. Turn off MySQL service
[Email protected] ~]# mysqladmin-uroot-poldboy123-s/data/3306/mysql.sock shutdown ==> via mysqladmin Shutdown gracefully shuts down the MySQL service. [Email protected] ~]# lsof-i:3306
2, use the--skip-grant-tables parameter background to start MySQL, ignore authorization authentication Direct login
[Email protected] ~]# mysqld_safe--defaults-file=/data/3306/my.cnf--skip-grant-tables & ==>-- Skip-grant-tables This parameter must be placed behind the default file,& indicates a background boot. [1] 63540[[email protected] ~]# 160216 22:27:26 mysqld_safe Logging to '/data/3306/mysql_oldboy3306.err '. 160216 22:27:26 Mysqld_safe starting mysqld daemon with databases From/data/3306/data^c[[email protected] ~]# lsof-i:3306command PI D USER FD TYPE DEVICE size/off NODE namemysqld 64277 mysql 12u IPv4 127392 0t0 TCP * : MySQL (LISTEN)
3. Log in to MySQL and use the UPDATE statement to modify the MySQL root password
[[email protected] ~]# mysql-s/data/3306/mysql.sock ==> did ignore authorization authentication, without password directly login; Welcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 1Server version:5.5.32-log Source distributioncopyright (c), +, Oracle and/or I TS affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> update mysql.user set Password=password ("oldboy123") where user= ' Root ' and host= ' localhost '; ==> use the UPDATE statement to modify the MySQL root password. Query OK, 0 rows affected (0.26 sec) rows matched:1 changed:0 warnings:0mysql> flush privileges; ==> Be sure to refresh the authorization table. Query OK, 0 rows affected (0.05 sec) mysql> \qbye
4. Log in to MySQL using the modified root password
[[email protected] ~]# mysql-uroot-poldboy123-s/data/3306/mysql.sock ==> Log in with the root password. Welcome to the MySQL Monitor.
At this point, retrieve and modify the root password successfully.
MySQL Root Password recovery