Modify the local database root privilege password

Source: Internet
Author: User

Method 1: Use the Set password commandTest Success

Log in to MySQL first

@1--mysql DOS window.
Format:mysql> set password for user name @localhost = password (' new password ');

mysql> flush Privileges; Refresh the permissions table in memory and take effect immediately
Example:mysql> set password for [email protected] = password (' admin ');

mysql> flush Privileges;

The above example changes the user root password to admin

@--using tool SQLyog to enter the database

( no database selected ) execution is also successful (compared to Method 2)!

Method 2: EnterMySQL DatabaseMake changesTest Success

After entering the MySQL DOS window, do not enter MySQL database directly to perform UPDATE USER SET PASSWORD = PASSWORD (' Dujie ') WHERE user= ' root ' and host= ' localhost ';

So remind No database selected

Correct practice:

After entering the MySQL DOS window, execute the following command

 1.use MySQL into MySQL database

2.UPDATE USER SET PASSWORD = PASSWORD (' Dujie ') WHERE user= ' root ' and host= ' localhost '; Update User Rights password

3.FLUSH privileges; Refresh the permissions table again.

Since MySQL starts, all user rights are loaded into memory, so a lot of permission checks can be faster, and you manually update just the table above the disk (but some permission update operations are not flushed to memory, so it only takes effect the next time you start),
Execute flush Privileges Writes the permissions table on the disk to memory, replacing the permissions table flush privileges in memory, forcing MySQL to reload the permissions so that the changes you just made take effect immediately.

  

Method 3:mysqladmin command to modify the user passwordThe test did not succeed

mysqladmin command format: Mysqladmin-u user Name----old password password new password

1) Add a password to root ab12
First enter directory Mysql\bin under DOS, and then type the following command:
Mysqladmin-u Root-password AB12
Note: Because Root does not have a password at the beginning, the-p old password can be omitted.

2) then change the root password to djg345
Mysqladmin-u root-p ab12 Password djg345

Method 4: When you forget the root password, you can do so.no tests .

Take windows as an example:
1. Close the running MySQL service.
2. Open the DOS window and go to the Mysql\bin directory.
3. Enter Mysqld--skip-grant-tables carriage return. --skip-grant-tables means skipping permission table authentication when starting the MySQL service .
4. Open a DOS window again (because the DOS window is no longer moving), go to the Mysql\bin directory.
5. Enter MySQL return and, if successful, the MySQL prompt > will appear.
6. Connection rights database: use MySQL;.
6. Change Password: Update user set Password=password ("admin10000.com") where user= "root"; (don't forget the last semicolon).
7. Refresh permissions (required steps): flush privileges;.
8. Quit quit.
9. Log out of the system, then enter, using the username root and the new password just set admin10000.com login.

Modify the local database root privilege password

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.