You can reset the root password for MySQL by following these steps:
1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily.
Because the MySQL database is completely password-protected during the reset of the root password of MySQL
Status, other users can also log in and modify MySQL information arbitrarily. MySQL can be used to
and stop Apache and all user processes to implement the server's quasi-security
State. The safest state is to operate on the console of the server and unplug the network cable.
2. To modify the login settings for MySQL:
# VI/ETC/MY.CNF in the paragraph of [mysqld]: Skip-grant-tables For example: [Mysqld] Datadir=/var/lib/mysql socket=/var/lib/mysql/ Mysql.sock Skip-name-resolve Skip-grant-tables
Save and Exit VI.
3. Restart Mysqld
#/etc/init.d/mysql Restart stopping mysql: [OK] starting MySQL: [OK]
4. Log in and modify the root password of 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 of table and column names You can turn off this feature to get a quicker startup with -a database changed mysql> update user set password = password ( ' New-password ' ) WHERE User = ' root ' ; Query OK, 0 rows affected (0.00 sec) rows matched: 2 changed: 0 warnings: 0 mysql> flush privileges ; query ok, 0 rows affected (0.01 SEC) mysql> quit bye
At the end of the day, add the line and delete it.
Skip-grant-tables
MySQL forgot root password