Change or reset password of MySQL user from terminal
If you have root access to your server and wish to change/ reset password of a MySQL user, then you can do via following method via terminal access to the server :
- Login into the server via root users.
- Type mysql (press enter) to enter into myql command prompt
Here we have got MariaDB, since the server has MariaDB.
3. Now you would need to run the following command :
mysql> UPDATE mysql.user SET Password=PASSWORD(‘text password’) WHERE user=”username” AND Host=”hostname”;
Update the ‘text password’ with the new password you want to set.
Username should be replaced with the mysql user, for which you need to update the password
hostname should be usually localhost. You can verify by running the following command :
mysql> select host, user, password from mysql.user;
It will display all the users with hashed password and their hosts.
4. Now to update the changes without restarting mysql service, run the following command :
mysql> FLUSH PRIVILEGES;
Whenever we grant some privileges for a user i.e updating the password or assigning a database, running the command flush privileges will reloads the grant tables in the mysql database enabling the changes to take effect without reloading or restarting mysql service.