How to create database and Tables in MySQL

database

Are you a PHP Programmer?. New Learner?. Then this is the correct place to learn about PHP and MySQL things.

In this post, I’m going to explain how to create a Database and Tables respectively.

1. Most of us are using PhpMyAdmin. So, it is not very difficult to create databases and tables!.

2. Open the PhpMyAdmin (for instance: https://localhost/phpmyadmin). The URL of your host may be different!.

3.  Creating a database is so easy. see the picture below.

mysql-db-create-step2

Type the database name in the textbox appear on the Home page of PhpMyAdmin and click “Create”. Here I typed “mydb” for example!
Now “mydb” database is available in the left sidebar of the PhpMyAdmin.

4. After you create the database immediately PhpMyAdmin will ask you to enter the table name to create a Table. So easy isn’t it?!

mysql-db-create-step3

See the above picture, Now enter a Table name and how many columns you need for the Table. Here, I enter “users” as the table name and the number of fields (columns) as “7”.  After you hit “Go” Button a table with three columns will be created!. See the picture below,

mysql-db-create-step7

5. Now enter the column names and set the type, See the picture below!

mysql-db-create-step5

In the above picture, I have given “user_id” as the first column name and set the type as “INT”. INT is nothing but Integer, Integers are numbers. “user_id” always be a number that’s why and see the “Index” row in the above picture there I have selected “PRIMARY” this is because “user_id” always should be Primary so no duplicate id will be created. Don’t forget to set the Length/Values. Here I put “10” which means I can create up to 10 digit numbers. (eg. 1234567891).

Second column as “username” and the type as “VARCHAR”. Like I said to use “INT” for numbers and “VARCHAR” for Strings (words, characters, etc) and give the required Length/Values. Normally for a username, it is required to give at least “30” as length.

Now other fields such as “password”, “fullname” and “email” are the same as the second column.

Sixth Column as “dob” and the type as “DATE”. The datatype “DATE” is for storing data. Always use the correct type to avoid confusion and problems!. No need to give the Length/Values here

Now click the Save button to finish creating the table!

You can see the created table in the left sidebar of the PHPMyAdmin like as shown in the below screenshot also the columns under the “Structure” tab,

mysql-phpmyadmin-structure

That’s it we have already created the table, now you can start inserting the records. Enjoy learning!

One thought on “How to create database and Tables in MySQL

Leave a Reply

Theme: Overlay by Kaira
Agurchand