Summary of several common ways to modify MYSQL password

  • 2020-06-01 11:10:09
  • OfStack

The first thing to declare is that most of the time you need to have root permission in mysql to modify MySQL.
So the user cannot change the password unless the administrator is requested. & shy;
Method 1 & shy;
Using phpmyadmin, which is the easiest, modify the user table of the mysql library.
But don't forget to use the PASSWORD function. & shy;
Method 2 & shy;
Use mysqladmin, which is a special case declared earlier. & shy;
mysqladmin -u root -p password mypasswd ­
After entering this command, you need to enter the original password for root, and then the password for root will be changed to mypasswd. & shy;
Change the root in the command to your username and you can change your own password. & shy;
Of course, if your mysqladmin can't connect to mysql server, or you can't perform mysqladmin.
Then this method is invalid. & shy;
And mysqladmin can't clear out the password. & shy;
The following methods are all used at the mysql prompt and must have mysql's root permissions: ­
Methods 3 & shy;
mysql > INSERT INTO mysql.user (Host,User,Password) ­
VALUES('%','jeffrey',PASSWORD('biscuit')); ­
To be exact, this is adding one user with the username jeffrey and password biscuit. & shy;
This example is in the Chinese reference manual of mysql, so I wrote it out. & shy;
Note that you use the PASSWORD function, and then you also use FLUSH PRIVILEGES. & shy;
Methods 4 & shy;
And method 31, just using the REPLACE statement ­
mysql > REPLACE INTO mysql.user (Host,User,Password) ­
VALUES('%','jeffrey',PASSWORD('biscuit')); ­
Methods 5 & shy;
Use SET PASSWORD statement, ­
mysql > SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit'); ­
The quasi must also use the PASSWORD() function, ­
But you don't need to use FLUSH PRIVILEGES. & shy;
Methods 6 & shy;
Using GRANT... IDENTIFIED BY statement ­
mysql > GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit'; ­
The PASSWORD() function is unnecessary here, and FLUSH PRIVILEGES is not required. & shy;
Note: PASSWORD() [not] enforces password encryption in the same way as Unix password encryption. & shy;
The solution to forgetting your password.
If MySQL is running, kill it first: killall-TERM mysqld. & shy;
Launch MySQL: bin/safe_mysqld -- skip-grant-tables & ­
You can access MySQL without a password. & shy;
And then there's the.
> use mysql­
> update user set password=password("new_pass") where user="root";­
> flush privileges;­
Re-kill MySQL and start MySQL the normal way. & shy;
Note: if you use phpmyadmin to change your password, you must use the encryption method. Otherwise, you cannot enter phpmyadmin! & shy;
It is recommended to use the command line to change the password.
After entering mysql ­
mysql > update mysql.user set password=password('new password');­
mysql > flush privileges;­
If you can't log in phpmyadmin after using phpmyadmin to modify your password, the easiest way is to reinstall phpmyadmin, just delete the original phpmyadmin folder, and then unzip phpmyadmin again. This method is a trick that comes to mind when I can't log in after modifying my password. & shy;

Related articles: