This guide will walk you through a couple of ways to change the password for a current user in MySQL.


1. For MySQL 5.7.6 and newer

  • Run the ALTER USER command:
ALTER USER 'user_name'@'host_name' IDENTIFIED BY 'new_password';
  • Or UPDATE the user table:
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User ='user_name' AND Host='host_name';
  • Or use the SET PASSWORD command:
SET PASSWORD FOR 'user_name'@'host_name' = 'new_password'

Sometimes it’s required to specify the current password while changing the password as to verify that the user attempting to make the change actually knows the current password. In that case, you have to add REPLACE:

ALTER USER 'user_name'@'host_name' IDENTIFIED BY 'new_password' REPLACE 'old_password';

Or

SET PASSWORD FOR 'user_name'@'host_name' = 'new_password' REPLACE 'old_password';


Note that REPLACE can be specified only when changing the account password for the current user.

Important note: Under some circumstances, SET PASSWORD may be recorded in server logs or on the client side in a history file such as ~/.mysql_history, which means that password in plaintext may be read by anyone having read access to that information. So for better security, use the ALTER USER command.

2. For MySQL 5.7.5 and older, run this command:

SET PASSWORD FOR 'user_name'@'hostname' = PASSWORD('new-password');

Finally, when you’re done changing the password, run this command so the changes can take effect immediately:

FLUSH PRIVILEGES;

New to TablePlus? It’s a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.


Download TablePlus here. It’s free anyway!

TablePlus GUI for MySQL