mysql root password reset method (pro test available)

  • 2020-06-07 05:27:03
  • OfStack

Attention! The hash tag is followed by the action.

1. Prerequisite Notes

First verify that the server is in a secure state, that no one can arbitrarily connect to the MySQL database.
Because during the MySQL root password reset, the MySQL database was completely unprotected
Other users can also log in and modify MySQL information at will. Use MySQL pairs instead
The external port is closed and Apache and all user processes are stopped to achieve the server's quasi-security
State. The safest state is to go to the server's Console and unplug.

2. Modify the login Settings of MySQL:
# vi /etc/my.cnf
Add a sentence to the paragraph [mysqld] : ES23en-ES24en-ES25en
Such as:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
Save and exit vi.

3. The method for restarting mysqld is as follows
#/etc/init.d/mysqld restart
StoppingMySQL: [ OK ]
Starting MySQL: [ OK ]

Other restart operation methods

service mysqld [start/stop/reboot] operate

4. Log in and change the root password for MySQL
# /usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql > USE mysql ;
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
mysql > UPDATE user SET Password = password ( 'new-password' ) WHERE User ='root' ;
Query OK, 0 rows affected (0.00 sec)
Rowsmatched: 2 Changed: 0 Warnings: 0
mysql > flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql > quit
Bye

5. Change the login Settings of MySQL back
# vi /etc/my.cnf
Delete the skip-ES105en-ES106en just added in the [mysqld] paragraph
Save and exit vi.

6. Restart mysqld
# /etc/init.d/mysqld restart
StoppingMySQL: [ OK ]
Starting MySQL: [ OK ]

root password reset successful!

Related articles: