Difference between revisions of "Update mysql user password"

From DevOps Notebook
 
(4 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';
+
Method 1: Using ALTER USER (MySQL 5.7.6+)
mysql> FLUSH PRIVILEGES;
+
<syntaxhighlight lang="sql">
 +
ALTER USER 'username'@'hostname' IDENTIFIED BY 'new_password';
 +
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>
 
</syntaxhighlight>
 
+
Or in MySQL 5.7.6+:
For earlier versions of mysql (mysql 5.7.6 or MariaDB 10.1.20 and earlier):
 
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">
mysql> SET PASSWORD FOR 'user-name'@'localhost' = PASSWORD('NEW_USER_PASSWORD');
+
SET PASSWORD = 'new_password';
mysql> FLUSH PRIVILEGES;
 
 
</syntaxhighlight>
 
</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';