Difference between revisions of "Update mysql user password"

From DevOps Notebook
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang="mysql">
+
<big>Few methods of changing mysql user password</big> <br> <br> <br>
mysql> ALTER USER 'user-name'@'some_host_ip' IDENTIFIED BY 'NEW_USER_PASSWORD';
 
mysql> FLUSH PRIVILEGES;
 
</syntaxhighlight>
 
 
 
 
 
 
Method 1: Using ALTER USER (MySQL 5.7.6+)
 
Method 1: Using ALTER USER (MySQL 5.7.6+)
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">

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';