简体   繁体   中英

Changing or resetting password for mysql user

how would look a simple query for Mysql database for resetting passwords

I have a example code of my, but it doesn't work and I'm not sure how to make it work

SELECT `User`, `Host`, Length(`Password`) FROM mysql.user
UPDATE mysql.user SET Password = PASSWORD('password') WHERE user = 'username';

and it doesn't work.

You don't need to select; only update.

update mysql.user set password=PASSWORD("NEW-PASSWORD-HERE") where User='USER';

Your problem may stem from the missing semi-colon after your select statement.

Try this:

SET PASSWORD FOR 'USER'@'HOST' = PASSWORD('PASSWORD');

Or, if you want to update the tables directly, don't forget to flush privileges.

UPDATE mysql.user SET Password = PASSWORD('PASSWORD') 
 WHERE user = 'USERNAME' AND Host='HOST';
FLUSH PRIVILEGES;

Finally, there is a third way using GRANT:

GRANT USAGE ON *.* TO 'USER'@'HOST' IDENTIFIED BY 'PASSWORD';

Reference: MySQL 5.7 Manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM