MySQL forgot root password solution

Source: Internet
Author: User
Tags mysql command line

one, can log in the changes, limited to the software recorded the password but I forgot Method 1: Use the Set password command

Log in to MySQL first.  
Format:mysql> set password for user name @localhost = password (' new password ');  
Example:mysql> set password for [email& Nbsp;protected] = password (' 123 ');  

Method 2: Mysqladmin  
Format: mysqladmin-u User name- P Old password password new password  
Example: mysqladmin-uroot-p123456 password 123 

Method 3: Edit the user table directly with update  
Log in to MySQL first.  
mysql> use mysql; 
mysql> Update user set Password=password (' 123 ') where user= ' root ' and host= ' localhost ';  
mysql> flush privileges; 
Second, unable to log on modify mode, limited to have permission to modify the MySQL installation file ()
Method 4: When you forget the root password, you can  
take windows as an example:  
1. Enter the MySQL installation directory to open the My.ini file

2. Locate the [mysqld] configuration line ( note, not [MySQL]), and enter it on the following line: Skip-grant-tables ( or:--skip-grant-tables, The difference is that sometimes two dashes will cause the service to fail to restart and the test should add No. )

3.cmd command: services.msc, find MySQL service and reboot ( make modified configuration file effective )

4.mysql command line: Use MySQL ( enter system Configuration library )

5.mysql command line: Update user set Password=password ("123") where user= "root"; ( don't forget the last semicolon, the semicolon means the end of the command )

6.mysql command line: Flush privileges; ( flush cache, update database read password do not forget the last semicolon, semicolon means the end of the command )

7. Log out of MySQL or restart the service and the password is set successfully.

MySQL forgot root password solution

Related Article

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.