Difference between revisions of "Update mysql user password"
From DevOps Notebook
(Created page with "<pre> mysql> ALTER USER 'user-name'@'some_host_ip' IDENTIFIED BY 'NEW_USER_PASSWORD'; mysql> FLUSH PRIVILEGES; </pre> For earlier versions of mysql (mysql 5.7.6 or MariaDB 10...") |
|||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | < | + | <big>Few methods of changing mysql user password</big> <br> <br> <br> |
| − | + | Method 1: Using ALTER USER (MySQL 5.7.6+) | |
| − | + | <syntaxhighlight lang="sql"> | |
| − | </ | + | ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password'; |
| − | + | FLUSH PRIVILEGES; | |
| − | For | + | </syntaxhighlight> |
| − | < | + | Method 2: Using SET PASSWORD |
| − | + | <syntaxhighlight lang="sql"> | |
| − | + | SET PASSWORD FOR 'username'@'hostname' = PASSWORD('new_password'); | |
| − | </ | + | FLUSH PRIVILEGES; |
| + | </syntaxhighlight> | ||
| + | For MySQL 5.7.6+ you can also use: | ||
| + | <syntaxhighlight lang="sql"> | ||
| + | SET PASSWORD FOR 'username'@'hostname' = 'new_password'; | ||
| + | FLUSH PRIVILEGES; | ||
| + | </syntaxhighlight> | ||
| + | Method 3: Using UPDATE (not recommended) | ||
| + | <syntaxhighlight lang="sql"> | ||
| + | UPDATE mysql.user SET Password = PASSWORD('new_password') | ||
| + | WHERE User = 'username' AND Host = 'hostname'; | ||
| + | FLUSH PRIVILEGES; | ||
| + | </syntaxhighlight> | ||
| + | Method 4: Using mysqladmin (command line) | ||
| + | bashmysqladmin -u username -p password new_password | ||
| + | Method 5: Change your own password | ||
| + | If you're changing your own password: | ||
| + | <syntaxhighlight lang="sql"> | ||
| + | SET PASSWORD = PASSWORD('new_password'); | ||
| + | </syntaxhighlight> | ||
| + | Or in MySQL 5.7.6+: | ||
| + | <syntaxhighlight lang="sql"> | ||
| + | SET PASSWORD = 'new_password'; | ||
| + | </syntaxhighlight> | ||
Latest revision as of 10:42, 8 August 2025
Few methods of changing mysql user password
Method 1: Using ALTER USER (MySQL 5.7.6+)
ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
Method 2: Using SET PASSWORD
SET PASSWORD FOR 'username'@'hostname' = PASSWORD('new_password');
FLUSH PRIVILEGES;
For MySQL 5.7.6+ you can also use:
SET PASSWORD FOR 'username'@'hostname' = 'new_password';
FLUSH PRIVILEGES;
Method 3: Using UPDATE (not recommended)
UPDATE mysql.user SET Password = PASSWORD('new_password')
WHERE User = 'username' AND Host = 'hostname';
FLUSH PRIVILEGES;
Method 4: Using mysqladmin (command line) bashmysqladmin -u username -p password new_password Method 5: Change your own password If you're changing your own password:
SET PASSWORD = PASSWORD('new_password');
Or in MySQL 5.7.6+:
SET PASSWORD = 'new_password';