If you’re a web developer or a database administrator, you know how important it is to keep your MySQL/MariaDB user passwords secure. But, how do you quickly and easily change your MySQL/MariaDB user password when you need to? In this guide, we’ll show you how to easily change your MySQL/MariaDB user password in just a few steps.
Login to the MySQL/MariaDB shell as root
Access the MySQL/MariaDB shell by typing the following command and enter your root user password when prompted:
mysql -u root -p
mariadb -u root -p
Set the MySQL/MariaDB user password
Type the following commands if you have MySQL 5.7.6 and later or MariaDB 10.1.20 and later.
ALTER USER 'user'@'%' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
Rename the MySQL/MariaDB user
Type the following commands if you have MySQL 5.7.6 and later or MariaDB 10.1.20 and later.
RENAME USER 'user'@'%' TO 'new_user'@'%';
FLUSH PRIVILEGES;
In both cases if all goes well, you will see the following output:
Query OK, 0 rows affected (0.00 sec)