MySQL sometimes forgets the root password. Here we provide a password reset method for Windows and Linux.
Windows:
1. log on to the system as a system administrator.
2. Open cmd ----- Net start to check whether MySQL is started. If it is enabled, the net stop MySQL will be stopped.
3. Install MySql in D: \ USR \ Local \ mysql4 \ bin.
4. Skip the permission check and start MySQL.
D: \ USR \ Local \ mysql \ bin \ mysqld-NT -- skip-grant-tables
5. Open cmd again. Enter D: \ USR \ Local \ mysql4 \ bin:
D: \ USR \ Local \ mysql \ bin \ mysqladmin-u root flush-Privileges password "newpassword"
D: \ USR \ Local \ mysql \ bin \ mysqladmin-u root-P shutdown prompts you to re-enter the password.
6. Net start MySql in cmd
7. You have done it.
Linux:
One of the methods to restore the MySQL Root Password
If you forget the MySQL Root Password, use the following method to reset it:
1. Kill the MySQL process in the system;
Killall-term mysqld
2. Run the following command to start MySQL without checking its permissions;
Safe_mysqld -- skip-grant-tables &
3. Use the empty password to log on to MYSQL as the root user;
Mysql-u Root
4. Modify the password of the root user;
Mysql> Update mysql. User SET Password = PASSWORD ('new password') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
Restart MySQL to log on with the new password.
Mysqlroot password restoration method 2
It is possible that your system does not have the safe_mysqld Program (for example, I am using the Ubuntu operating system, MySQL installed with APT-Get). The following method can be restored:
1. Stop mysqld;
Sudo/etc/init. d/MySQL stop
(You may have other methods. Simply stop running mysqld)
2. Run the following command to start MySQL without checking its permissions;
Mysqld -- skip-grant-tables &
3. Use the empty password to log on to MYSQL as the root user;
Mysql-u Root
4. Modify the password of the root user;
Mysql> Update mysql. User SET Password = PASSWORD ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
Restart MySQL
/Etc/init. d/MySQL restart
You can use the new password newpassword to log on.
The above content is an introduction to the solution to the problem of forgetting the MySQL root password. I hope you will gain some benefits.
From: http://it.oyksoft.com/post/6438/