Method 1: Use phpmyadmin, which is the simplest. Modify the user table of the mysql database, but do not forget to use the PASSWORD function. Method 2: Use mysqladmin, which is a special case stated above. Mysqladmin-uroot-ppasswordmypasswd after entering this command, enter the original root password and change the root password to mypa.
Method 1: Use phpmyadmin, which is the simplest. Modify the user table of the mysql database, but do not forget to use the PASSWORD function. Method 2: Use mysqladmin, which is a special case stated above. Mysqladmin-u root-p password mypasswd input this command, you need to enter the original root password, then the root password will be changed to mypa
Method 1
Use phpmyadmin, which is the simplest. Modify the user table of the mysql database, but do not forget to use the PASSWORD function.
Method 2
Use mysqladmin, which is a special case stated above.
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.
Change the root in the command to your username, and you can change your password.
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.
The following methods are used at the mysql prompt and must have the root permission of mysql:
Method 3
Mysql> Insert INTO mysql. user (Host, User, Password)
VALUES (%, jeffrey, PASSWORD (biscuit ));
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. You must use the PASSWORD function and then use flush privileges.
Method 4
Similar to method Sany, but the REPLACE statement is used.
Mysql> replace into mysql. user (Host, User, Password)
VALUES (%, jeffrey, PASSWORD (biscuit ));
Mysql> FLUSH PRIVILEGES
Method 5
Use the set password statement
Mysql> set password for jeffrey @ "%" = PASSWORD (biscuit );
You must use the PASSWORD () function, but do not need to use flush privileges.
Method 6
Use the GRANT... identified by statement
Mysql> grant usage on *. * TO jeffrey @ "%" identified by biscuit;
Here, the PASSWORD () function is unnecessary and does not need to be flush privileges.
Note: PASSWORD () [not] implements PASSWORD encryption in the same way as Unix PASSWORD encryption.
How to fix MySQL password loss
If MySQL is running, first:
Killall-TERM mysqld
Start MySQL:
Bin/safe_mysqld -- skip-grant-tables &
You can access MySQL without a password.
Then
> Use mysql
> Update user set password = password ("new_pass") where user = "root ";
> Flush privileges;
Kill MySQL again and start MySQL in a normal way.
Clear Mysql password
Windows
1. log on to the system as a system administrator;
2. Stop MySQL services;
3. Go to the Command window and enter the MySQL installation directory. For example, if my installation directory is c: mysql, go to C: mysqlin;
4. Skip permission check to start MySQL
C: mysqlin> mysqld-nt -- skip-grant-tables
5. open a new window, enter the c: mysqlin directory, and set the new root password.
C: mysqlin> mysqladmin-u root flush-privileges password "newpassword"
C: mysqlin> mysqladmin-u root-p shutdown
Replace newpassword with the root password you want to use. The second command will prompt you to enter a new password and repeat the password entered by the First Command;
6. Stop MySQL Server and start Mysql in normal mode;
7. You can use a new password to link to Mysql.
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;
3. Use the -- skip-grant-tables parameter to start MySQL Server
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 password change
To modify Mysql, run the following command on the Mysql command line:
Mysql-u root mysql
Mysql> Update user SET password = PASSWORD ("new password") Where user = name;
Mysql> flush privileges;
Mysql> QUIT
How to restore the password of a MySQL database
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.
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
User. MYD // user table data file
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, just copy user. MYD.
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 the mysql password in Windows 2003.
Mysql> use mysql
Mysql> update user set Password = PASSWORD (xxxxxx) where User = root;
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, the permissions are 666 at ls-l.
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 ls-l under/var/lib/mysql /.
# Chown-R mysql: mysql user .*
# Chmod 600 user .*
// OK, DONE
Restart MYSQL and try again.
Mysql> use mysql
Mysql> update user set Password = PASSWORD (xxxxxx) where User = root;
Mysql> flush privileges;
NOTE: If mysql is configured by default in windows, you must execute
Mysql> delete from user where User =;
Mysql> delete from user where Host = %;
Mysql> flush privileges;
Now, the password recovery process is complete. 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)
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.
Killall-TERM mysqld
You must be a UNIX root user or an equivalent user on the SERVER you run to perform this operation.
2. Use the '-- skip-grant-tables parameter to start mysqld. In LINUX:
/Usr/bin/safe_mysqld -- skip-grant-tables, c: mysqlinmysqld in windows
-- Skip-grant-tables
3. log on to the 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. Load the permission table:
Mysqladmin-h hostname flush-privileges
Or use SQL commands
FLUSH PRIVILEGES
5.
Killall-TERM mysqld
6. Log On with the new password.
Other method 2
Directly use the hexadecimal editor to edit the user. MYD file.