Solution for restoring MySQL Database root Password 2

Source: Internet
Author: User

The following article describes how to restore the root password of a MySQL database. The following describes how to restore the root password of a MySQL database. I hope to help you in this regard.

Method 1

1. Download the MySQL source code distribution package. We don't need to differentiate the operating system. We need the same thing;

2. Rename the mysql folder in the data directory of your mysql database to oldmysql;

3. Copy the mysql directory under the data directory in the source code package to the data directory of your mysql;

4. Restart mysql. Now the mysql authorization relationship is the same as that of the new installation. log on with a blank password and adjust the authorization;

5. Open the database oldmysql to check what is going on;

6. If there is a backup, the integrity of the original database in the system will be checked to avoid modification.

Method 2

1. Send the kill command to the mysqld server to disable the mysqld server (not kill-9). The files that store the process ID are usually located in the directory of the MYSQL database.

 
 
  1. kill `cat /mysql-data-directory/hostname.pid` 

You must be the root user of Linux or the same user on the SERVER where you are running;

 
 
  1. killall -TERM mysqld 

2. Use the '-- skip-grant-tables' parameter to start mysqld;

 
 
  1. shell>mysqld_safe --skip-grant-tables &  
  2. / bin/safe_mysqld --skip-grant-tables &  

3. Use the 'mysql-h hostname mysql' command to log on to the mysqld server and use the grant command to change the password. You can also do this:

 
 
  1. `mysqladmin -h hostname -u user password ’new password’’ 

It can also be used

 
 
  1. use mysql; update user set passwordpassword =password(’yourpass’) where user=’root’ 

MySQL database;

 
 
  1. shell>mysqladmin -u root flush-privileges password "newpassword"  
  2. >use mysql  
  3. >update user set passwordpassword=password("new_pass") where user="root";  
  4. >flush privileges;  

4. Load the permission table:

 
 
  1. mysqladmin -h hostname flush-privileges’ 

Or use SQL commands

 
 
  1. `FLUSH PRIVILEGES’ 

Of course, you can restart mysqld here. Hope to help you! The above content is an introduction to the root password of the MySQL database. I hope you will have some gains.

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.