MySQL command line, you can modify the MySQL database password, the following for you to detail the MySQL command line, if you are interested, may wish to see.
Format: Mysqladmin-u username-P Old password password new password
1, to root add a password ab12. First enter the directory Mysqlbin in DOS, and then type the following command
Mysqladmin-u Root-password AB12
Note: Since Root does not have a password at the beginning, the-p old password can be omitted.
2, and then the root of the password changed to djg345.
Mysqladmin-u root-p ab12 Password djg345
(Note: Unlike the above, the following are the commands in the MySQL environment, followed by a semicolon as the command Terminator)
3, the command line to modify the root password:
mysql> UPDATE mysql.user SET password=password (' New password ') WHERE user= ' root ';
mysql> FLUSH privileges;
4, display the current user:
Mysql> SELECT USER ();
The above is remember the password if you forget the root password can refer to the following method to solve
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.
PostScript, because the recovery process is more fun, so write a note, don't hit me
Do you have any other fun methods do not forget to tell me oh:
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.
The
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.