How to modify the MySQL root password

Source: Internet
Author: User
Tags manual flush mysql in mysql tutorial php tutorial mysql command line

About How to modify the MySQL tutorial root password We have listed a lot of changes on the mysql password , okay crap don't say much more we look at these days to modify the root password effective means and methods.
Method One

Using the PHP tutorial MyAdmin, this is the easiest, to modify the MySQL library's user table, but don't forget to use the password function. Www.111cn.net

Method Two Www.111cn.net

Using Mysqladmin, this is a special case of the previous declaration.

Www.111cn.net

Mysqladmin-u root-p Password mypasswd

After entering this command, you need to enter the original password for root, and then the root password will be changed to MYPASSWD. Www.111cn.net

Change the command root to your username, and you can change your password. Www.111cn.net

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.

Www.111cn.net

The following methods are used at the MySQL prompt and must have the root permissions of MySQL :

Method Three Www.111cn.net

Mysql> Insert into Mysql.user (Host,user,password) www.111cn.net

VALUES ('% ', ' Jeffrey ', PASSWORD (' biscuit ')); Www.111cn.net

Mysql> FLUSH Privileges

To be exact, this is adding a user, the username is Jeffrey, and the password is biscuit.

This example is available in the MySQL Chinese reference manual:

Www.111cn.net

Note that you want to use the password function, and then use flush privileges.

Method Four

And method Three, just use the Replace statement www.111cn.net

Mysql> REPLACE into Mysql.user (Host,user,password)

VALUES ('% ', ' Jeffrey ', PASSWORD (' biscuit ')); Www.111cn.net

Mysql> FLUSH Privileges

Method Five Www.111cn.net

Using the Set Password statement,

Mysql> SET PASSWORD for jeffrey@ "%" = PASSWORD (' biscuit ');

Www.111cn.net


You must also use the password () function, but you do not need to use flush privileges.

Www.111cn.net


Method Six

Use Grant ... Identified by statement

Www.111cn.net

Mysql> GRANT USAGE on *.* to jeffrey@ "%" identified by ' biscuit ';

Www.111cn.net

Here the password () function is unnecessary and does not require the use of flush privileges. Www.111cn.net

Note: PASSWORD () [is not] the password encryption is performed in the same way as the UNIX password encryption.

Www.111cn.net

MySQL Forgot Password Solution


If MySQL is running, first kill: Killall-term mysqld.

Start Mysql:bin/safe_mysqld--skip-grant-tables & Www.111cn.net

You can enter MySQL without the need for a password. Www.111cn.net

And then there's www.111cn.net.

>use MySQL

>update User Set Password=password ("New_pass") where user= "root"; Www.111cn.net

>flush privileges;

Re-kill MySQL, the normal way to start MySQL.

Www.111cn.net


MySQL Password empty

Windows:

1. Login system with system administrator.

Www.111cn.net


2. Stop the MySQL service.

Www.111cn.net


3. Enter the command window, and then enter the MySQL installation directory, such as my installation directory is c:mysql, into the C:mysqlbin www.111cn.net

4. Skip permission Check to start MySQL,

Www.111cn.net


C:mysqlbin>mysqld-nt--skip-grant-tables www.111cn.net

5. Reopen a window, enter the C:mysqlbin directory, set the new password for root

C:mysqlbin>mysqladmin-u root flush-privileges password "NewPassword" www.111cn.net

C:mysqlbin>mysqladmin-u root-p shutdown

Www.111cn.net

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

Www.111cn.net


7. You can link to MySQL with a new password.

Www.111cn.net


Unix&linux:

1. User login system with root or running mysqld;


2. Use KILL command to end the process of mysqld;

Www.111cn.net


3. Start MySQL Server with the--skip-grant-tables parameter

Shell>mysqld_safe--skip-grant-tables & Www.111cn.net

4. Set a new password for root@localhost www.111cn.net

Shell>mysqladmin-u root flush-privileges password "NewPassword"

Www.111cn.net


5. Restart MySQL Server

Www.111cn.net

MySQL Modify password

Www.111cn.net

MySQL modifications can be performed on the MySQL command line as follows: Www.111cn.net

Mysql-u Root MySQL www.111cn.net

mysql> Update user SET Password=password ("New password") Where user= ' name ';

mysql> FLUSH privileges;

Www.111cn.net


Mysql> QUIT

Www.111cn.net

Teach you how to restore the MySQL database tutorial password

Www.111cn.net


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.

Www.111cn.net


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

Www.111cn.net

User. MyD//user table Data file www.111cn.net

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 www.111cn.net

Then Www.111cn.net

#. /etc/rc.d/init.d/mysql stop

#. /etc/rc.d/init.d/mysql start

Www.111cn.net


#mysql-U root-p XXXXXX


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

Www.111cn.net

Mysql>use MySQL Www.111cn.net

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

Www.111cn.net


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

Www.111cn.net

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.*

Www.111cn.net

#chmod user.*

Www.111cn.net

Ok,done

Re-start MySQL www.111cn.net

Re-connect

Www.111cn.net

Mysql>use MySQL Www.111cn.net

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

Www.111cn.net


Mysql>flush privileges;

Www.111cn.net


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

Www.111cn.net


Mysql>delete from user where user= ';

Www.111cn.net


Mysql>delete from user where host= '% ';

Www.111cn.net


Mysql>flush privileges;

All right, here we go. The process of restoring the password is complete www.111cn.net

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)

Www.111cn.net

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.

Www.111cn.net

Killall-term mysqld

You must be a UNIX root user or an equivalent user on the server you are running to perform this operation.

Www.111cn.net

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 www.111cn.net

3. Then login to mysqld Server without a password,

Www.111cn.net

>use MySQL Www.111cn.net

>update User Set Password=password ("New_pass") where user= "root";

Www.111cn.net


>flush privileges; Www.111cn.net

You can also do this:

Www.111cn.net


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

4. Loading permission table:

Www.111cn.net

mysqladmin-h hostname flush-privileges '

or use the SQL command www.111cn.net

FLUSH privileges '


5.killall-term mysqld

Www.111cn.net

6. Login with new password

Other method Two

Www.111cn.net


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 Www.111cn.net

Fixed: My actual operation under Windows is as follows Www.111cn.net

1. Close the running MySQL. Www.111cn.net

2. Open the DOS window and go to the Mysqlbin directory.

Www.111cn.net

3. Input

Mysqld-nt--skip-grant-tables

Enter. If you don't get a hint, that's it. Www.111cn.net

4. Open a DOS window again (because the DOS window is already unable to move), go to the Mysqlbin directory. Www.111cn.net

5. Enter MySQL return, if successful, will appear MySQL prompt >

Www.111cn.net

6. Connection Rights Database Www.111cn.net

>use MySQL;

Www.111cn.net


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

6. Change Password: www.111cn.net

> Update user Set Password=password ("123456") where user= "root"; (Don't forget the last semicolon) www.111cn.net

7. Refresh permissions (required steps)

Www.111cn.net

>flush privileges;

8. Exit

> Q

9. Logout system, re-enter, open MySQL, use user name root and just set the new password 123456 login.

Www.111cn.net

It is said that you can use the method of directly modifying the user table file:

Www.111cn.net

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. Www.111cn.net

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, enter root and your new 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.