Difference between revisions of "Update mysql user password"
From DevOps Notebook
| Line 4: | Line 4: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | ||
| + | Method 1: Using ALTER USER (MySQL 5.7.6+) | ||
<syntaxhighlight lang="sql"> | <syntaxhighlight lang="sql"> | ||
| − | + | ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password'; | |
| − | mysql | + | FLUSH PRIVILEGES; |
| + | </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> | </syntaxhighlight> | ||
Revision as of 10:40, 8 August 2025
mysql> ALTER USER 'user-name'@'some_host_ip' IDENTIFIED BY 'NEW_USER_PASSWORD';
mysql> FLUSH PRIVILEGES;
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';