MySQL forgot the super user admin password, can take advantage of restarting the MySQL process with the--skip-grant-tables parameter to start the database, and a blank password login. This is the equivalent of the first time the database was started. You can then view the super users in the Mysql.user table and modify the Superuser's password
# close MySQL instance, or kill the process
* Restart MySQL with--skip-grant-tables statement
[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘
3# Empty password login MySQL
[[email protected] my.cnf.d]$ msyql -S /data/mysqldata/3306/mysql.sock bash: msyql: command not found...[[email protected] my.cnf.d]$ mysql -S /data/mysqldata/3306/mysql.sock Welcome to the MySQL monitor.
4# Modifying the Mysql.user table
([email protected])[(none)]> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed([email protected])[mysql]> ([email protected])[mysql]> select user,host,password from user;+------+-----------+-------------------------------------------+| user | host | password |+------+-----------+-------------------------------------------+| root | localhost | *A0F874BC7F54EE086FCE60A37CE7887D8B31086B |+------+-----------+-------------------------------------------+1 row in set (0.00 sec)([email protected])[mysql]> update user set password=password(‘password123‘) where user=‘root‘;Query OK, 0 rows affected (0.00 sec)Rows matched: 1 Changed: 0
AA Normal Shutdown database
[[email protected] my.cnf.d]$ mysqladmin -S /data/mysqldata/3306/mysql.sock -uroot -p‘password123‘ shutdownWarning: Using a password on the command line interface can be insecure.180828 19:04:54 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended[1]+ Done
6# Normal Open Database
[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘ &[1] 33094[[email protected] my.cnf.d]$ 180828 19:05:04 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.180828 19:05:04 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data[[email protected] my.cnf.d]$
7# Normal Login Database
[[email protected] my.cnf.d]$ mysql -uroot -S ‘/data/mysqldata/3306/mysql.sock‘ -p‘password123‘Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.
The root password of MySQL has been modified to complete
MySQL forgot root password