This brief tutorial shows students and new users how to change MySQL or MariaDB database user password to something strong and unique which might help improve your system security. This post applies to both MySQL and MariaDB database servers. Since both use the same underlying code. MariaDB is a drop-in replacement for MySQL. So, in the future you decide to switch from MySQL to MariaDB, you should just be able to do it without impacting applications. When you’re ready to learn how to change database users’ passwords, follow the steps below: Before changing the MySQL user password, you may want to consider the following:

The account you want to update Applications if any, the account is used for connecting to the database and how strong the password should be

When you’re ready, continue. MySQL provides various statements that you can use to change the password of a user including the UPDATE, SET PASSWORD, and ALTER statements. These statements are different but perform the same functions. As shown above, there are many ways to change MySQL user passwords. One way to change a user’s password is to use the UPDATE statement to update the user table of the mysql database.

Use the UPDATE statement to change the password

For example, if you want to change the admin user password to something unique like password_1234 on the local database server, you run the SQL statement below: The FLUSH PRIVILEGES  statement to reload privileges from the grant table in the mysql database. The SQL commands above will change the admin user password to password_1234 If you use MySQL 5.7.6+, you must use the authentication_string column in the UPDATE statement. So, run the statement below to change/update the MySQL user password: Again, the commands above only work with MySQL 5.7.6 and up.

Use the SET PASSWORD statement to change the password

You can also use the SET PASSWORD  statement to change the MySQL user password. Run the SQL statement below to change the admin password: Or use the statement below for MySQL 5.7.6 up

Use the ALTER USER statement to change the password

Finally, you can use the ALTER USER statement to change the MySQL user password. To do that, run the commands below: Always flush privileges when done making changes to the password so the table can be reloaded. That’s it! These are some of the ways to change MySQL users’ passwords.  This might come in handy if you need to update MySQL user passwords on your server. Enjoy!