How to Set MySQL Root Password using phpMyAdmin

Do you want to change the password for the root account of your MySQL server? Sometimes you may want to set a password for the ‘root’@’localhost’ account. In this article, I show you 3 possible ways to reset the password for your root account.

When your application is live, you have to pass both the username and password in order to access the database. For accessing phpMyAdmin on a live server, your hosting does set the credentials for you. But on the local server, you have to set credentials yourself. Though users rarely set the password on the local machine to access phpMyadmin, it’s always a good practice to do so.

That being said, let’s take a look at how to set MySQL Root password. I am going to show you 3 different ways of resetting the password.

How to Set Root Password in phpMyAdmin

phpMyAdmin is a fantastic software built for handling your MySQL databases. It just makes the developer’s life easy to manage the database, tables, table structures, queries, and so on.

Using phpMyAdmin, one can set the Root password in a few steps.

Go to the phpMyAdmin on the browser. Most probably you can access it using http://localhost/phpmyadmin.

Click on the ‘User Accounts’ from the top bar.

User Accounts

You will then see a list of user accounts. We need the last account from the list with the User name as ‘root’ and the Host name as ‘localhost’. Click on the ‘Edit privileges’ from the Action column of this row.

Edit Privileges

On the next screen, click on ‘Change password’. In the form, enter the password you want to set and click on ‘Go’.

Change Password

After these steps are done, head over to your editor and open the config.inc.php from the phpmyadmin directory. On my Windows 10 machine, I have an XAMPP server installed and config.inc.php path is D:\xampp\phpMyAdmin\config.inc.php. Adjust the path as per your installations.

Search for $cfg['Servers'][$i]['auth_type'] in the file config.inc.php. This variable should have a ‘config’ value set by default. Change this value to ‘cookie’ as follows.

$cfg['Servers'][$i]['auth_type'] = 'cookie';

Run the URL http://localhost/phpmyadmin on the browser and this time you will be asked for entering username and password. Enter the username as ‘root’ and the password which you set in the above steps, it will log you inside the phpMyAdmin.

Keep a note you have to use the same username and password in your database connection code for the applications.

This is the most efficient way of changing the Root password. However, there are 2 other ways to set the password for the ‘root’@’localhost’ account.

Other Ways to Set MySQL Root Password

If you want to try another way of changing a Root password, then first revert back to the changes made in the config.inc.php file.

$cfg['Servers'][$i]['auth_type'] = 'config';

Head over to phpMyAdmin, click on the ‘SQL’ from the top bar, and run the below query.

SET PASSWORD FOR root@localhost = PASSWORD('PASSWORD_HERE');

Replace the placeholder with the actual value. Set again the ‘cookie’ value for the $cfg['Servers'][$i]['auth_type'] variable of your config.inc.php file and you are done.

The last option to reset the Root password is through the command line. For this, you again need to revert your changes of config.inc.php file.

If you have set the MySQL path in your environment then you can run the MySQL queries directly in the command prompt. If the path is not set, then open the terminal inside the MySQL installation directory. In my case, its path is D:\xampp\mysql\bin.

In the terminal, run the below command:

mysqladmin -u root password PASSWORD_HERE
Command Prompt

After this, set the value as ‘cookie’ for the $cfg['Servers'][$i]['auth_type'] variable.

That’s it! I hope you got to know how to set MySQL Root password using phpMyAdmin and terminal. Please share your thoughts and suggestions in the comment section below.

Related Articles

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

1 thought on “How to Set MySQL Root Password using phpMyAdmin

Leave a Reply

Your email address will not be published. Required fields are marked *