[Windows]
1. Stop MySQL service: Open the command line window CMD and net stop MySQL
2. Start MySql in another way: Use mysqld-nt.exe to start MySql in the directory of the installation directory of mysqlin the command line:
Mysqld-NT -- skip-grant-tablesNote: The cmd window cannot be closed.
3. Enter MYSQL: In addition, open a command line window and execute MySql in the bin directory. You do not need to enter a password.
> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;
> Exit
Note:
1) if you are familiar with SQL statements, update does not need to explain that the first user is the table name and the second user is the field in the table. The first password is the table field, and the second password () is the encryption function. New_pass is the password to be changed.
2) flush privileges does not need to be added. However, you must note that the Host field cannot be localhost. Because after using this method, you cannot connect with localhost. You can change this field to an IP address or a wildcard character.
> Update user set host = "192.168.0.1" where user = "root"
4. Use the task manager to locate the mysqld-nt process and end the process!
5. Restart the MySQL service and use the new password to log on to net start MySQL.
[Linux]
1. Close MYSQL: If MySQL is running, killall-term mysqld will be killed first.
2. Use another method to start MYSQL: Bin/safe_mysqld -- skip-grant-tables &
3. You can enter MySQL without a password.
> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;
Note: Same as above
4. Kill MySQL again and start MySql in a normal way.