How can I forget the root password of MySQL in Linux?
Verification Environment:
[Root @ localhost ~] # Rpm-qa | grep mysql
Mysql-5.1.71-1.el6.i686
Mysql-server-5.1.71-1.el6.i686
Mysql-libs-5.1.71-1.el6.i686
[Root @ localhost ~] # Lsb_release-
LSB Version: core-4.0-ia32: core-4.0-noarch: graphics-4.0-ia32: graphics-4.0-noarch: printing-4.0-ia32: printing-4.0-noarch:
Distributor ID: CentOS
Description: CentOS Linux release 6.0 (Final)
Release: 6.0
Codename: Final
[Root @ localhost ~] # Uname-r
2.6.32-71. el6.i686
1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will.
Because during the resetting of the MySQL root Password, the MySQL database is completely out of the password-free status, other users can also log on and modify the MySQL information at will. You can disable the external port of MySQL and stop Apache and all user processes to implement the quasi-security status of the server. 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. 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
[Root @ localhost ~] # Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3
Server version: 5.1.71 Source distribution
Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql> UPDATE mysql. user SET Password = password ("new-password") WHERE User = 'root ';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
Mysql> exit
Bye
5. Modify the MySQL Logon Settings.
# Vi/etc/my. cnf
Delete the skip-grant-tables added to the [mysqld] segment, save the settings, and exit vi;
6. Restart mysqld again
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
7. log on with a new password. Log On normally!
Solution for Windows/Linux MySQL to forget the root password
How to solve the problem of forgetting the root password of MySQL
Change the root password for MySQL
How to reset the root password of the MySQL server in Ubuntu
Restore the MySQL root Password under Red Hat