How to set the MySQL root password in localhost using WAMP

In this post I will like to show you how to set the MySQL root account password in 3 different ways.

This is a very important step in your WAMP Server setup and although is not required for local development, I still suggest creating a root password as good practice. If you are using WAMP to share your website online then I STRONGLY recommend a strong password with upper and lower case letters and numbers and perhaps throwing in a couples of symbols too.

The 3 ways I will be discussing here are, 1) by going to the MySQL console and typing the appropriate commands, 2) via the GUI (graphical user interface) using SQL Buddy and 3) via PHPMyAdmin.

Lets begin,

1. Using the MySQL Console

On the wamp menu go to MySQL –> MySQL console.

mySQL-console

Hit enter as there is no password. Enter the following commands:

mysql> SET PASSWORD for 'root'@'localhost' = password('enteryourpassword');
mysql> SET PASSWORD for 'root'@'127.0.0.1' = password('enteryourpassword');
mysql> SET PASSWORD for 'root'@'::1' = password('enteryourpassword');

That’s it, I keep the passwords the same to keep things simple. If you want to check the user’s table to see that the info has been updated just enter the additional commands as shown below. This is a good option to check that you have indeed entered the same password for all hosts.

mysql-console-root-password

2. Using SQL Buddy

This is the way I typically do it. Just open SQL Buddy and go to the Users option on the left. Select all host with a user root and click ‘edit’.

sqlbuddy-edit-user-password

Enter your password for all users and hit ‘submit’ for each user. Each time you hit submit you will see a message:  ‘Your changes were saved to the database’.

sqlbuddy-edit-user-password-submit

That’s it. And again you can check the User table in the mysql database to check that you have entered the same password for all hosts.

sqlbuddy-edit-user-table

SQL Buddy will log you out and take you back to the login screen after once you have changed the root password. Have no fear, just enter your new password on the log in screen and you should be fine.

3. Using phpMyAdmin

Go to http://localhost/phpmyadmin/ and click on USER

Installing-and-configuring-wamp-server-phpmyadmin-1

On one of the root accounts click on ‘Edit Privileges’. Enter the new password twice and click on ‘GO’. Do this for the remaining root accounts. I suggest making the password the same for all three accounts.

Installing-and-configuring-wamp-server-phpmyadmin-2
Installing-and-configuring-wamp-server-phpmyadmin-3

Just like SQL Buddy, phpMyAdmin will log you out once you have changed the root password. In this case, you will get an error if you have not configured phpMyAdmin to prompt you for a password.

Here is how to fix this error:

Installing-and-configuring-wamp-server-phpmyadmin-error
Error #1045 – Access denied for user ‘root’@’locahost’ (using password: yes)

Open the config.inc.php file found in C:\wamp\apps\phpmyadmin4.1.x and look for /* Authentication type */ around line 28.

Set your password for the root account by entering it between the single quotes ‘ ‘ in the following line:

$cfg['Servers'][$i]['password'] = 'mypassword';
Installing-and-configuring-wamp-server-phpmyadmin-config.inc

Replace mypassword with your own password of course. This should get you back to phpMyAdmin.

Hope this post has helped in your local web development efforts.

If you have any feedback or suggestions please leave a comment on the section below.

Thanks for visiting 🙂

46 Comments on “How to set the MySQL root password in localhost using WAMP

    1. If you got the #1045 error you will need to update the config.inc.php file with your new password. (see the last part of the post above). Hope this helps.

  1. Great post.
    Appreciate simple way to get rid of one of the most annoying issues with mysql/phpMyAdmin.
    Thanks!

    Could you please give some tips of how to stop uncertain mysql crash on wamp server as a result of accidental abrupt shutdown of the system?

  2. whenever i m trying to login into my project its always show. “Username or Password not recognised :(“. Somebody tell me what y im unable to do so? what should i need to change in my code or db.?
    thxx a lot.

  3. Error
    MySQL said: Documentation

    #1045 – Access denied for user ‘root’@’localhost’ (using password: YES)
    mysqli_real_connect(): (HY000/1045): Access denied for user ‘root’@’localhost’ (using password: YES)
    phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server

    I tried everything but didn’t work. 🙁

  4. I got ERROR 1133 (42000): can’t find any matching row in the user table.. what should i do now ?

  5. Thanks for your help brooo u gave us a usefull system but i have a question,
    how can you restore your password when you forget the one you a using before????

  6. Thank you for this helpful post.

    I do have a question. Can you explain the significance of $cfg[‘Servers’][$i][‘password’] = ‘mypassword’ ?

    1. In case you get the error shown on the post, then this is the line on the config.inc.php file where you would enter the password you have set for the root account. You would replace mypassword with your own password.

  7. I have been looking for a solution to this problem for 3 hours now. I was developing a website for a client and got locked out of phpmyadmin. I can’t thank you more!!!

  8. hey when i tried to change the password it didn’t work instead the mySQl console instead of showing MySQL> is showing ‘root@localhost-MySQL8.0.21-[‘none’]>

Please Post Your Comments & Reviews

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.