In linux, the root password of mysql is forgotten. 1. First, check that the server is in a safe state, that is, no one can connect to the MySQL database.
Because, during the resetting of the MySQL root password, the MySQL database is completely out of password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. The safest status is to operate on the server Console and unplug the network cable.
2. modify MySQL logon settings :.
# vi /etc/my.cnf
In the [mysqld] section, add skip-grant-tables.
For example:
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables
Save and exit vi.
3. restart mysqld
# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
4. log on to and modify the MySQL root password
# /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
5. modify the MySQL logon settings.
# vi /etc/my.cnf
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit vi.
6. restart mysqld
# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
OK. All operations have been completed.