As for how to modify the mysql root Password, we have listed a lot of changes to the mysql password. Let's take a look at the effective methods and methods to change the root password over the past few days.
AboutHow to modify the mysql root PasswordWe listed a lotMysql passwordLet's take a look at the effective methods and methods to change the root password over the past few days.
Method 1
Using the php tutorial myadmin, This is the simplest. Modify the user table of the mysql database, but do not forget to use the PASSWORD function. Www. bKjia. c0m
Method 2 www. bKjia. c0m
Use mysqladmin, which is a special case stated above.
Www. bKjia. c0m
Mysqladmin-u root-p password mypasswd
After entering this command, you need to enter the original root password, and then the root password will be changed to mypasswd. Www. bKjia. c0m
Change the root in the command to your username, and you can change your password. Www. bKjia. c0m
Of course, if your mysqladmin cannot connect to mysql server, or you cannot execute mysqladmin, this method is invalid, and mysqladmin cannot clear the password.
Www. bKjia. c0m
The following methods are used at the mysql prompt and must containRoot permission of mysql:
Method 3 www. bKjia. c0m
Mysql> Insert INTO mysql. user (Host, User, Password) www. bKjia. c0m
VALUES ('%', 'Jeffrey ', PASSWORD ('biscuit'); www. bKjia. c0m
Mysql> FLUSH PRIVILEGES
Specifically, this is adding a user with the username jeffrey and password biscuit.
This example is provided in mysql Chinese Reference Manual:
Www. bKjia. c0m
Be sure to use the PASSWORD function, and then use flush privileges.
Method 4
The REPLACE statement www. bKjia. c0m is used.
Mysql> replace into mysql. user (Host, User, Password)
VALUES ('%', 'Jeffrey ', PASSWORD ('biscuit'); www. bKjia. c0m
Mysql> FLUSH PRIVILEGES
Method 5 www. bKjia. c0m
Use the set password statement,
Mysql> set password for jeffrey @ "%" = PASSWORD ('biscuit ');
Www. bKjia. c0m
You must use the PASSWORD () function, but do not need to use flush privileges.
Www. bKjia. c0m
Method 6
Use the GRANT... identified by statement
Www. bKjia. c0m
Mysql> grant usage on *. * TO jeffrey @ "%" identified by 'biscuit ';
Www. bKjia. c0m
Here, the PASSWORD () function is unnecessary and does not need to be flush privileges. Www. bKjia. c0m
Note: PASSWORD () [not] implements PASSWORD encryption in the same way as Unix PASSWORD encryption.
Www. bKjia. c0m
How to fix MySQL password loss
If MySQL is running, killall-TERM mysqld is first killed.
Start MySQL: bin/safe_mysqld -- skip-grant-tables & www. bKjia. c0m
You can access MySQL without a password. Www. bKjia. c0m
Then www. bKjia. c0m
> Use mysql
> Update user set password = password ("new_pass") where user = "root"; www. bKjia. c0m
> Flush privileges;
Kill MySQL again and start MySQL in a normal way.
Www. bKjia. c0m
Clear mysql password
Windows:
1. log on to the system as a system administrator.
Www. bKjia. c0m
2. Stop MySQL services.
Www. bKjia. c0m
3. Enter the command window and enter the MySQL installation directory. For example, if my installation directory is c: mysql, enter C: mysqlbin www. bKjia. c0m.
4. Skip the permission check and start MySQL,
Www. bKjia. c0m
C: mysqlbin> mysqld-nt -- skip-grant-tables www. bKjia. c0m
5. open a new window, enter the c: mysqlbin directory, and set the new root password.
C: mysqlbin> mysqladmin-u root flush-privileges password "newpassword" www. bKjia. c0m
C: mysqlbin> mysqladmin-u root-p shutdown
Www. bKjia. c0m
Replace newpassword withRoot Password, The second command will prompt you to enter a new password, repeat the password entered by the first command.
6. Stop MySQL Server and start Mysql in Normal Mode
Www. bKjia. c0m
7. You can use a new password to link to Mysql.
Www. bKjia. c0m
Unix & Linux:
1. log on to the system using root or a user running mysqld;
2. Use the kill command to end the mysqld process;
Www. bKjia. c0m
3. Use the -- skip-grant-tables parameter to start MySQL Server
Shell> mysqld_safe -- skip-grant-tables & www. bKjia. c0m
4. Set the new password www. bKjia. c0m for root @ localhost.
Shell> mysqladmin-u root flush-privileges password "newpassword"
Www. bKjia. c0m
5. Restart MySQL Server
Www. bKjia. c0m
Mysql password change
Www. bKjia. c0m
To modify mysql, run the following command on the mysql command line: www. bKjia. c0m
Mysql-u root mysql www. bKjia. c0m
Mysql> Update user SET password = PASSWORD ("new password") Where user = 'name ';
Mysql> flush privileges;
Www. bKjia. c0m
Mysql> QUIT
Www. bKjia. c0m
How to restore the password of the MySQL database tutorial
Www. bKjia. c0m
Because the MySQL password is stored in the user table in the mysql database, you only need to copy the user table in MySQL under windows 2003 to overwrite it.
Www. bKjia. c0m
In c: mysqldatamysql (linux, there are three user table related files in the/var/lib/mysql/) Directory: user. frm, user. MYD, user. MYI
User. frm // user Table Style File
Www. bKjia. c0m
User. MYD // user table data file www. bKjia. c0m
User. MYI // user table index file
For the sake of insurance, all three are copied. However, if the table structure has not been changed on the MySQL to be restored, you only need to copy user. MYD to www. bKjia. c0m.
Then www. bKjia. c0m
#./Etc/rc. d/init. d/mysql stop
#./Etc/rc. d/init. d/mysql start
Www. bKjia. c0m
# Mysql-u root-p XXXXXX
Okay, you can log in with the mysql password in windows 2003.
Www. bKjia. c0m
Mysql> use mysql www. bKjia. c0m
Mysql> update user set Password = PASSWORD ('xxxxxx') where User = 'root ';
Www. bKjia. c0m
An error occurs, prompting that the user table has only the read permission.
I analyzed the reason. This is the only reason, because the permissions assigned to the user. * file are in windows 2003, and in windows 2003, my ls-l permission is 666.
Www. bKjia. c0m
In linux, I can see that after copying the file, the permission is changed to 600 (in fact, under normal circumstances, only the file owner here is not mysql, the copied owner is changed to root, so there will be insufficient permissions. At this time, if you change to 666 permissions, It will be okay, of course, this is not good, there is no substance to solve the problem ), check the ls-l in/var/lib/mysql /.
# Chown-R mysql: mysql user .*
Www. bKjia. c0m
# Chmod 600 user .*
Www. bKjia. c0m
// OK, DONE
Restart MYSQL www. bKjia. c0m
Reconnect
Www. bKjia. c0m
Mysql> use mysql www. bKjia. c0m
Mysql> update user set Password = PASSWORD ('xxxxxx') where User = 'root ';
Www. bKjia. c0m
Mysql> flush privileges;
Www. bKjia. c0m
NOTE: If mysql is configured by default in windows, you must execute
Www. bKjia. c0m
Mysql> delete from user where User = '';
Www. bKjia. c0m
Mysql> delete from user where Host = '% ';
Www. bKjia. c0m
Mysql> flush privileges;
Now, the password recovery process completes www. bKjia. c0m.
This method has some limitations. You must have another user table file.
There are several other methods
Other methods 1 (this is a widely spread method on the internet, mysql Chinese Reference Manual)
Www. bKjia. c0m
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.
Www. bKjia. c0m
Killall-TERM mysqld
You must be a UNIX root user or an equivalent user on the SERVER you run to perform this operation.
Www. bKjia. c0m
2. Use the '-- skip-grant-tables' parameter to start mysqld. In LINUX:
/Usr/bin/safe_mysqld -- skip-grant-tables, c: mysqlbinmysqld -- skip-grant-tables www. bKjia. c0m in windows
3. log on to the mysqld server without a password,
Www. bKjia. c0m
> Use mysql www. bKjia. c0m
> Update user set password = password ("new_pass") where user = "root ";
Www. bKjia. c0m
> Flush privileges; www. bKjia. c0m
You can also do this:
Www. bKjia. c0m
Mysqladmin-h hostname-u user password 'new password''
4. Load the permission table:
Www. bKjia. c0m
Mysqladmin-h hostname flush-privileges'
Or run the SQL command www. bKjia. c0m.
FLUSH PRIVILEGES'
5. killall-TERM mysqld
Www. bKjia. c0m
6. log in with a new password
Other method 2
Www. bKjia. c0m
Directly use the hexadecimal editor to edit the user. MYD File
But here I want to explain that I found a problem when editing here. Some encrypted password strings are stored continuously, and some of the last two digits are cut, the last two digits are stored in other places. I haven't understood this yet. note that the encrypted password string is edited, that is, you still need to have another user table file. The difference between this method and the method I introduced above is that this method directly edits the user table file in linux, and does not need to re-Modify the file owner and the permission to www. bKjia. c0m.
Correct: My actual operations on Windows are as follows: www. bKjia. c0m
1. Disable running MySQL. Www. bKjia. c0m
2. Open the DOS window and go to the mysqlbin directory.
Www. bKjia. c0m
3. Input
Mysqld-nt -- skip-grant-tables
Press enter. If no prompt is displayed, it is correct. Www. bKjia. c0m
4. Open another DOS window (because the DOS window can no longer be moved) and go to the mysqlbin directory. Www. bKjia. c0m
5. Enter mysql and press Enter. If yes, a MySQL prompt is displayed.>
Www. bKjia. c0m
6. Connect to the permission database www. bKjia. c0m
> Use mysql;
Www. bKjia. c0m
(> It is an existing prompt. Don't forget the last Semicolon)
6. Change the password: www. bKjia. c0m
> Update user set password = password ("123456") where user = "root"; (don't forget the last semicolon) www. bKjia. c0m
7. Refresh permissions (required steps)
Www. bKjia. c0m
> Flush privileges;
8. Exit
> Q
9. log out of the system, log on to MySQL, and log on to MySQL with the username "root" and the new password "123456.
Www. bKjia. c0m
It is said that you can directly modify the user table file:
Www. bKjia. c0m
Close MySQL and open Mysqldatamysql in Windows. There are three file users. frm, user. MYD, user. MYI finds a MySQL with a password and replaces these three files. If the user table structure has not been changed, no one will change it. Replace the user. MYD. Www. bKjia. c0m
You can also directly edit user. MYD and find a hexadecimal editor. UltraEdit has this function. Close MySQL and enable user. MYD. Change the eight characters after the root user name to 565491d704013245, and the new password is 123456. Or change the hexadecimal numbers corresponding to them (one character on the left corresponds to two numbers) to 00 02 02 02 02 02 02 02 02 02. This is an empty password, the asterisk * is displayed on the right of the editor, which looks like a decimal point. Restart MySQL and enter root and your new password.