Several methods of cracking MySQL root password

Source: Internet
Author: User
Tags flush mysql in mysql command line

 


Several ways to hack the MySQL root password on the Internet:
Method One
uses phpMyAdmin, which is easiest to modify the user table in the MySQL library, but don't forget to use the password function.
Method Two
uses Mysqladmin, which is a special case of the previous declaration.
mysqladmin-u root-p Password mypasswd
When you enter this command, you need to enter the original password for root, and then the password for root will be changed to MYPASSWD.
Change the root of the command to your username, and you can change your password.
Of course, if your mysqladmin is not connected to MySQL server, or you have no way to execute mysqladmin, then this method is invalid, and mysqladmin cannot empty the password.
The following methods are used at the MySQL prompt and must have the root permissions of MySQL:
Method three
Mysql> Insert into Mysql.user (host,user,password)
VALUES ('% ', ' Jeffrey ', PASSWORD (' biscuit '));
Mysql> FLUSH Privileges
Specifically, this is adding a user, the user name is Jeffrey, and the password is biscuit.
There is this example in the MySQL Chinese reference manual, so I wrote it.
Note that you want to use the password function, and then use flush privileges.
Method Four
, like method Three, uses only the Replace statement
Mysql> replace into Mysql.user (Host,user,password)
VALUES ('% ', ' Jeffrey ' , PASSWORD (' biscuit '));
Mysql> FLUSH Privileges
Method Five
uses the Set PASSWORD statement,
Mysql> set PASSWORD for jeffrey@ "%" = PASSWORD (' Biscu It ');
You must also use the password () function, but you do not need to use flush privileges.

Method Six
Use Grant ... Identified by statement
Mysql> GRANT USAGE on *.* to jeffrey@ "%" identified by ' biscuit ';
Here the password () function is unnecessary and does not require the use of flush privileges.

Note: PASSWORD () [is not] the password encryption is performed in the same way as the UNIX password encryption.
MySQL Forgot Password Solution
If MySQL is running, first kill: Killall-term mysqld.
Start Mysql:bin/safe_mysqld–skip-grant-tables &
You can enter MySQL without the need for a password.
Then it's
>use MySQL
>update User Set Password=password ("New_pass") where user= "root";
>flush privileges;
Re-kill MySQL, the normal way to start MySQL.

MySQL Password empty
Windows:
1. Login system with system administrator.
2. Stop the MySQL service.
3. Enter the command window, and then enter the MySQL installation directory, such as my installation directory is c:mysql, into the C:mysqlbin
4. Skip permission Check to start MySQL,
C:mysqlbin>mysqld-nt–skip-grant-tables
5. Reopen a window, enter the C:mysqlbin directory, set the new password for root
C:mysqlbin>mysqladmin-u root flush-privileges password "NewPassword"
C:mysqlbin>mysqladmin-u root-p shutdown
Replace the newpassword with the root password you want to use, and the second command prompts you to enter a new password and repeat the password entered in the first command.
6. Stop MySQL Server, start MySQL in normal mode
7. You can link to MySQL with a new password.
Unix&linux:
1. User login system with root or running mysqld;
2. Use KILL command to end the process of mysqld;
3. To start the MySQL Server with the –skip-grant-tables parameter
Shell>mysqld_safe–skip-grant-tables &
4. Set a new password for root@localhost
Shell>mysqladmin-u root flush-privileges password "NewPassword"
5. Restart MySQL Server

MySQL Modify password
MySQL modifications can be performed on the MySQL command line as follows:
Mysql-u Root MySQL
mysql> Update user SET Password=password ("New password") Where user= ' name ';
mysql> FLUSH privileges;
Mysql> QUIT

Teach you how to restore the MySQL database password
Because the MySQL password is stored in the user table in database MySQL, just copy the user table from my Windows 2003 MySQL to cover it.
In C:mysqldatamysql (Linux is generally in/var/lib/mysql/mysql/) directory has three user table related files user.frm, user. MyD, user. Myi
User.frm//user Table Style file
User. MyD//user Table Data file
User. Myi//user Table Index file
To be on the safe side, three copies are copied, but in fact if you have not changed the table structure on the MySQL that you want to restore, just copy user. MyD on the line.
And then

#. /etc/rc.d/init.d/mysql stop
#. /etc/rc.d/init.d/mysql start
#mysql-U root-p XXXXXX

Okay, you can log in with Windows 2003 MySQL password.

Mysql>use MySQL
Mysql>update user Set Password=password (' xxxxxx ') where user= ' root ';

There will be an error, prompting the user table with Read permission only
I analyzed the reason, just like this, because the user.* file's permission assignment is under Windows 2003, under Windows 2003 I ls-l see the permission is 666
When I look at Linux, cuff after the permission to become 600 (in fact, the normal situation 600 on the line, but here is the file is not MySQL, the owner of the copy came to root, so there will be insufficient permissions, this time if you change to a permission of 666 can, of course, this is not good, Did not solve the problem of the substance), under the/var/lib/mysql/mysql/Ls-l looked at
Again

#chown-R Mysql:mysql user.*
#chmod user.*

Ok,done
Re-start MySQL
Re-connect

Mysql>use MySQL
Mysql>update user Set Password=password (' xxxxxx ') where user= ' root ';
Mysql>flush privileges;

One thing to note: If you have windows under MySQL if it is the default configuration, note that you have to perform

Mysql>delete from user where user= ";
Mysql>delete from user where host= '% ';
Mysql>flush privileges;

All right, here's the procedure to recover the password.

This method is a bit of a limitation, you must also have another user table file
################################################################################
There are several other ways
Other methods one (this is a popular online method, MySQL Chinese reference manual)
1. Send Kill command to MYSQLD server to turn off MYSQLD server (not kill-9), and the file that holds the process ID is usually in the directory where the MySQL database resides.

Killall-term mysqld

You must be a UNIX root user or an equivalent user on the server you are running to perform this operation.
2. Use the ' –skip-grant-tables ' parameter to start the mysqld. Linux under:

/usr/bin/safe_mysqld–skip-grant-tables, Windows C:mysqlbinmysqld–skip-grant-tables

3. Then login to mysqld Server without a password,

>use MySQL
>update User Set Password=password ("New_pass") where user= "root";
>flush privileges;

。 You can also do this:

`
Mysqladmin-h hostname-u user password ' new password '

4. Loading permission table:

`
mysqladmin-h hostname flush-privileges '

or use SQL commands

' FLUSH privileges '

5.
Killall-term mysqld

6. Login with new password

################################################################################
Other method Two
Edit user directly with the hexadecimal editor. MyD file
But here I want to make it clear that I found a problem when I edited it, some of the encrypted cipher strings were stored continuously, some of the last two bits were cut, The latter two bits are stored in the back of the other place. I'm not sure about that yet. Also note that editing is the encrypted password string, which means you still need to have a user table file. The difference between this approach and the one I described above is that this method directly edits the user table file under Linux without having to change the file owner and permissions.
Fix it: My actual operation under Windows is as follows
1. Close the running MySQL.
2. Open the DOS window and go to the Mysqlbin directory.
3. Input

Mysqld-nt–skip-grant-tables

Enter. If you don't get a hint, that's it.
4. Open a DOS window again (because the DOS window is already unable to move), go to the Mysqlbin directory.
5. Enter MySQL return, if successful, will appear MySQL prompt >
6. Connection Rights Database

>use MySQL;
(> is the original prompt, don't forget the last semicolon)

6. Change Password:

> Update user Set Password=password ("123456″") where user= "root"; (Don't forget the last semicolon)

7. Refresh permissions (required steps)

>flush privileges;

8. Exit

> Q

9. Logout system, re-enter, open MySQL, use user name root and just set the new password 123456 login.
It is said that you can use the method of directly modifying the user table file:
Close Mysql,windows Open Mysqldatamysql, there are three files User.frm,user. Myd,user. Myi find a password to know the MySQL, replace the corresponding three files, if the user table structure has not changed, generally no one to change, replace user. MyD is OK.
You can also edit the user directly. MyD, find a hexadecimal editor, UltraEdit has this function. Turn off MySQL and open user. MyD. Change the eight characters after user name root to 565491d704013245, and the new password is 123456. Or they correspond to the hexadecimal digits (two digits to the left, a character), to 00 02 02 02 02 02 02 02, which is the blank password, and the right side of the editor is an asterisk *, which looks like a decimal point. Re-open MySQL and enter root and your new password.

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.