This article summarizes several methods to change the mysql password, one is to change your mysql password when you remember, one is that you do not remember how to retrieve or modify the mysql password.
This article summarizes several methods to change the mysql password, one is to change your mysql password when you remember, one is that you do not remember how to retrieve or modify the mysql password.
How to set a password for mysql
There are many methods:
1. After Entering mysql with root
Mysql> set pass = password ('your password ');
Mysql> flush privileges;
2. Use the GRANT statement
Mysql> grant all on *. * to 'root' @ 'localhost' identified by 'your password' with grant option; www.2cto.com
Mysql> flush privileges;
3. Go to the mysql database to modify the user table
Mysql> use mysql;
Mysql> update user set password = password ('your password') where user = 'root ';
Mysql> flush privileges;
How to forget the mysql password
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.
Environment:/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 without a password.
Run the following statement to update the root password to 7758521:
Update user set password = PASSWORD ("7758521") 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.
Modification completed.
Try it with the new password 7758521. Is it different if you can log on to MySQL again?
Other solutions
Reset the root password
Method 1:
Add the following to the [mysqld] field of my. ini:
Skip-grant-tables
Restart the mysql service. mysql can log on to the database without a password.
Then go to mysql
Mysql> use mysql;
Mysql> Update user set password = password ('new password') WHERE User = 'root ';
Mysql> flush privileges;
After running the command, remove skip-grant-tables from my. ini and restart mysqld.