This article summarizes how to set the mysql password on linux and windows servers. For more information, see.
This article summarizes how to set the mysql password on linux and windows servers. For more information, see.
Mysql in windows
(Applicable to Resetting passwords of other users by administrators or users with global permissions)
Enter command line mode
| The Code is as follows: |
|
Mysql-u root mysql
Mysql> UPDATE user SET password = PASSWORD ("new password") WHERE user = 'name ';
Mysql> flush privileges;
Mysql> QUIT |
Method 2:
(The application is the same as above, but the method is different)
| The Code is as follows: |
|
Mysql-u root mysql
Mysql> set password for name = PASSWORD ('new password ');
Mysql> QUIT |
(I am not commonly using the above two methods. If I am an administrator, I will use other tools such as phpmyadmin or MYSQL-front to manage user permissions, Which is intuitive and convenient)
Quick Summary
| The Code is as follows: |
|
|
A ../mysqladmin-u root-p oldpassword newpasswd (remember this command is an external command in/usr/local/mysql/bin)
B. SET PASSWORD FOR root = PASSWORD ('new password'); (this method is used after logging on to the database)
C. UPDATE user SET password = PASSWORD ("new password") WHERE user = 'root'; (this method is used after logging on to the database) |
Mysql in linux
Method 1:
The simplest method is the method prompted by the system after mysql is installed. Use mysqladmin.
| The Code is as follows: |
|
|
Shell> mysqladmin-u root password "newpwd"
Shell> mysqladmin-u root-h host_name password "newpwd" password |
Double quotation marks are not mandatory. However, if the password contains spaces or special symbols, use quotation marks. Method 2: Use the set password command in MySQL to SET the root PASSWORD. Note that you must use the PASSWORD () function to encrypt the newpwd, otherwise, directly = 'newpwd' will not take effect. However, if you use mysqladmin password or GRANT to set the PASSWORD, you do not need to use the password () function because they have automatically called this function.
| The Code is as follows: |
|
|
Shell> mysql-u root
Mysql> set password for 'root' @ 'localhost' = PASSWORD ('newpwd ');
Mysql> set password for 'root' @ 'host _ name' = PASSWORD ('newpwd '); |
Method 3:
Set the password directly through the UPDATE user table
| The Code is as follows: |
|
|
Shell> mysql-u root
Mysql> UPDATE mysql. user SET Password = PASSWORD ('newpwd ')
-> WHERE User = 'root ';
Mysql> flush privileges; |
If you forget the mysql root Password, perform the following steps to reset it:
1. Kill all mysql Processes
2. Use the -- skip-grant-tables parameter to start mysql.
| The Code is as follows: |
|
|
Shell> mysqld_safe -- skip-grant-tables & |
The ultimate killer:
| The Code is as follows: |
|
|
Mysqladmin-u root "old password" "new password" |
Solution: If you have a name, use your username instead. If you have a new password, enter the password you want to set.