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.
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.
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’.
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’.
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.
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
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.
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:
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';
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 🙂
thanks for this useful post working fine for me
Glad to hear it Santhosh. Thanks for the comment.
excellent sir, it works on wamp and easy to follow. thank u so much.
You are very welcome Afzal. Thanks for your comment.
i generate a code but i forgot it what should i do?
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.
Thanks! Great!!
i cant find automatic startup in the wamp settings
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?
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.
Thanks so much – This worked for me 🙂
Best wishes xo
yes that realy helpful
really worked well..
thanks a lot
…
Glad it worked sathya. Thanks for the comment 🙂
thanks. Helpful.
Just what i needed. Thanks Henry
Good job.It is very usefull.
Thanks for this clear, comprehensive and useful solution. Just what I needed.
Glad it was helpful Mike. Thanks for the comment.
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. 🙁
You tried connecting after or before you set the root password?
how did you resolve that?
Henry , U are just nice. U r teaching the world. Keep it up bro
aw sheesh, thank you for the comment Gift 🙂
I got ERROR 1133 (42000): can’t find any matching row in the user table.. what should i do now ?
Thank you very much
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????
I am not aware of how to recover it. You would have to reset it via the DB.
Thank you for this helpful post.
I do have a question. Can you explain the significance of $cfg[‘Servers’][$i][‘password’] = ‘mypassword’ ?
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.
Your post was really helpful and easy to follow. Thank you!
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!!!
Thanks for awesome article
I forgot my phpmyadmin root password. How can I recover/reset it?
Thank you! this was very useful.
Stopped me from nearly crying of despair.
Welcome to phpMyAdmin
Wrong username/password. Access denied. got htis error when i tried to load http://localhost/phpmyadmin/ please help…
Thank you a lot.
This post solved my problem.
thank you so much
Thanks a lot. it works !
Glad it worked 🙂
Thanks so much, it works fine and good.
You are welcome 🙂
This article saved my night man! Million thanks!
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’]>
Hi vinicius, if you are on Windows, try this: https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
thank you!