1. Edit the MySQL configuration file:
In Windows: % mysql_installdir %/My. ini // In the MySQL installation directory, my. INI is the configuration file of MySQL.
In Linux:/etc/My. CNF
Add the following line in the [mysqld] configuration section:
Skip-grant-tables
Save and exit editing.
2. Restart the MySQL service.
In Windows:
Net stop MySQL
Net start MySQL
In Linux:
/Etc/init. d/mysqld restart
3. Set a new root password.
Then run the following command in the command line:
Mysql-uroot-P MySQL
Press enter to enter the database without a password.
Run the following statement to update the root password to 123456:
Update user SET Password = PASSWORD ("123456") where user = 'root ';
Quit exits MySQL.
4. Restore the configuration file and restart the service.
Then, modify the MySQL configuration file and delete the row that you just added.
Restart the MySQL service again and the password is changed.
First: mysql> Update user SET Password = PASSWORD ('new _ password') where user = 'root ';
Mysql> flush privileges;
Second:
Mysql> set password for root = PASSWORD ('new _ password ');
Third:
Shell> mysqladmin-u Root Password new_password;
Information from: China self-learning Network (www. cnzixue. com) detailed source reference: http://www.cnzixue.com/html/web/DataBase/2009/1107/3526.html