Contents
1. What is Mysqladmin :
Mysqladmin is a command-line utility the comes with MySQL server and it is used by Database Administrators to perform some basic MySQL tasks easily such as setting root password, changing root password, monitoring mysql processes, reloading privileges, checking server status etc.
2. Method N° 1 : Change a Password for MySQL on Linux via Command Line :
Step 1: Connect to your database server:
First we’ll login to the MySQL server from the command line with the following command:
1 2 |
[user@localhost $] mysql -u root -p Enter password: |
Enter the administrator password you set up during installation.
Step 2: Switch to MySQL database :
After connect to MySQL server with root you should switch to the appropriate MySQL database with the following command:
1 2 3 4 |
mysql> use mysql ; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> |
Step 3: Update the password for MySQL root user:
Next we’ll update the password for MySQL root user. Be sure to replace your_new_password with the actual new password:
1 2 3 4 5 6 |
mysql> update user set password=PASSWORD('your_new_password') where User='root' ; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> mysql> mysql> |
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root.
Finally, reload the privileges and exit MySQL:
1 2 3 4 5 6 7 8 |
mysql> flush privileges ; Query OK, 0 rows affected (0.00 sec) mysql> mysql> mysql> quit ; Bye root@localhost:~# |
3. Method N° 2: Use mysqladmin command to change root password :
if you want to change (or update) a root password, then you need to use the following command:
1 2 |
root@localhost:~# mysqladmin -u root -p'OldPassword' password NewPassword root@localhost:~# |
4. Conclusion
In this post, i have explained how to Change a Password for MySQL Root User on Linux.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂