How to modify the mysql password and forget the mysql password

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.