Create Database in MySQL Command Line Windows Tutorial

There are various graphic softwares available to deal with Mysql database. No one is capable of accessing all the features and options of Mysql database. The Mysql command line interface is used because it can access all the features and options of Mysql database.

How to Use Mysql Command Line Interface in Windows 7?

To run Mysql command line interface you can go to the Start Manu in the left bottom corner of your screen in windows 7. Click on the start menu and type “cmd” in the search field and press Enter or Click on the cmd.exe file.

mysql-cmd-1After running cmd you will see the command line interface. Now you can use mysql command line interface if you have installed mysql in your computer. If you have not installed mysql yet please see installing XAMP in windows or installing WAMP in windows to install MySQL database. After installing you have to run mysql first to use in command line interface. Now you have to type “mysql” and you are in the MySQL command line interface.



To connect to a database you have to have 3 things. You need host, username and password to connect to a database. If you have installed MySQL separately then you would have given username and password. If you are using the XAMP or WAMP then they both have “root” as username and the password is empty. The host is localhost in both WAMP and XAMP packages. The root user has all the privileges and it is like an administrator.

You can run SQL queries in the mysql command line interface. See the example below where we are showing the databases and the current datetime with two SQL queries.


In the above picture we are using the command “show databases” to show all the databases and “select NOW()” to show the current datetime.

If you want to connect to a particular database you can type “use database_name” and MySQL command line interface will show you that it has changed the database. Now you can create table see tables etc.

To use the command line with root user you should type like this “mysql –u root”.

How to change the root password in MySQL command line interface?

All the users in mysql are stored in a table called users. To change the root user password or any user password you should type

Mysql-> UPDATE mysql.user SET Password = PASSWORD(‘mypassord’) WHERE User = ‘root’;

After running this command you should tell mysql to reread the user table get the effects. To tell mysql to reread the tables we use following command:


Now exit from the root user and again login with the old user name and empty password you will not be able to login now. You have to type the password to login as following:

C:Usersemily>mysql –u root –p (press enter)

Enter password: *********

After entering the password you will be able to login to the database as a root user now.