This brief tutorial shows students and new users how to change MySQL or MariaDB database user passwords to something substantial and unique, which might help improve your system security.
Learning how to change MariaDB user passwords on Ubuntu Linux is important for improving the security of your system. Passwords are the first line of defense against unauthorized access to your database, and it’s essential to ensure that they are strong and unique.
By changing your MariaDB user passwords regularly, you can help prevent unauthorized access to your database and protect your data from theft, corruption, or loss.
Additionally, it’s a good practice to change passwords whenever an employee or a user who had access to your database leaves your organization.
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 you can use to change a user’s password, 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:
USE mysql; UPDATE user SET password = PASSWORD('password_1234') WHERE user = 'admin' AND host = 'localhost'; FLUSH PRIVILEGES;
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:
USE mysql; UPDATE user SET authentication_string = PASSWORD('password_1234') WHERE user = 'admin' AND host = 'localhost'; FLUSH PRIVILEGES;
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:
USE mysql; SET PASSWORD FOR 'admin'@'localhost' = PASSWORD('password_1234');
Or use the statement below for MySQL 5.7.6 up
USE mysql; SET PASSWORD FOR 'admin'@'localhost' = 'password_1234';
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:
USE mysql; ALTER USER 'admin'@'localhost' IDENTIFIED BY = 'password_1234';
Always flush privileges when changing the password so the table can be reloaded.
That’s it!
These are some of the ways to change MySQL users’ passwords. This might be useful if you update MySQL user passwords on your server.
Enjoy!
Leave a Reply Cancel reply