MySQL sometimes forget the root password is a sad thing, in this case, how to reset the root password it?
Locate and edit the MySQL my.ini configuration file and add skip-grant-table to the Mysqld node. as follows:
# This let you safely reset the lost root password.
Skip-grant-table
Save the changes and restart the MySQL service.
You can now connect to the database without the root password. Then perform the following update:
Use MySQL;
UPDATE USER
SET password = password (' yournewpasswordhere ')
WHERE USER = ' root ' and
host = ' localhost ';
So the root password is modified, this time, the My.ini in the skip-grant-table Delete, and then restart the MySQL service
The following is a description of the password reset method under Windows and Linux.
Windows:
1. Log in as a system administrator.
2. Open cmd-----net start to see if MySQL starts. Stop the net stop MySQL when you start.
3. My MySQL is installed under the D:\usr\local\mysql4\bin.
4. Skip permission check to start MySQL.
D:\usr\local\mysql\bin\mysqld-nt--skip-grant-tables
5. Reopen cmd. Into the 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 This sentence prompts you to lose the password again.
6. In the cmd net start MySQL
7. It's done.
Linux:
One of the ways to restore MySQL root password
If you forget the MySQL root password, you can reset it in the following ways:
1. Kill off the MySQL process in the system;
Killall-term MySQLd
2. Use the following command to start MySQL, to do not check the permissions of the way to start;
Safe_mysqld--skip-grant-tables &
3. Then use the null password method to log in to MySQL with root user;
Mysql-u Root
4. Change the password of root user;
mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root ';
mysql> flush Privileges;
Mysql> quit
Restart MySQL and you can log on with the new password.
Mysqlroot Password recovery Method two
It is possible that your system does not have SAFE_MYSQLD programs (such as I now use the Ubuntu operating system, Apt-get installed MySQL), the following methods can be restored
1. Stop mysqld;
Sudo/etc/init.d/mysql stop
(You may have other methods, in short stop the mysqld run on it)
2. Use the following command to start MySQL, to do not check the permissions of the way to start;
MySQLd--skip-grant-tables &
3. Then use the null password method to log in to MySQL with root user;
Mysql-u Root
4. Change the password of 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 log on using the new password NewPassword.