Saturday, 14 June 2014

Changing default mysql password in WAMP server.


WAMP is "Windows, Apache, MySQL, and PHP", an application server platform.
You can download it from WAMP site.
 Default password for mysql is String with no length. So on getting prompt for password simply pressing enter would log you into the mysql console as root.

Understanding the architecture

Lets understand where this password for root use is stored. We can then see how can we go modifying it. To start with open mysql console. It will ask for password simply press enter. You should see the following screen.

Next take a look at the databases that come preconfigured. For that simply execute 

mysql > show databases;

You should get some databases. The database we are interested in is mysql database. So go ahead and and execute

mysql > use mysql;

You should get message database changed. See following screen shot

If you wish to see tables in this database you can do

mysql > show tables;

You will see all the tables in this mysql database. The table we are interested in is the table user.

If you want to see what columns make up this table user and what is its data type you can execute following command.

mysql > describe user;

  You can see a lot of columns in the table. But columns that are of our interest are Host, User and Password. Host is the URL. Like you can have localhost or etc. User is the user for which the row is. Example can be the root (This is the user for which we will be changing the password). But you can also have other users and add new users. Finally password is the password that the particular user enter when he logs into mysql console.

Now we know that the default password is a String with no length i.e "". Lets verify this
 Run following command - 

 mysql > select host,user,password from user where user='root';

This should show you that the password is a blank value.

Changing the password

With the above background lets change our password. Execute the following command

mysql > update user set password=PASSWORD('newpassword') where user='root';

(Replace newpassword with your password) .

Note : Password will be stored as encrypted String.

Then you can verify that the tables are indeed changes using previous query

 mysql > select host,user,password from user where user='root';

 Now you will have to flush privileges.

mysql > flush privileges;

You have changed your password successfully. Next time you login to mysql console you will have to enter this password. To exit mysql console simple use exit command.

mysql > exit

Related Links

No comments:

Post a Comment

t> UA-39527780-1 back to top