Web Info and IT Lessons Blog...

Friday 24 October 2014

Inroduction and Basics of MySql

Database skills are must for a professional web developer. In this lesson we will learn about one of the most widely used open-source relational database management system (RDBMS) MySQL also known as "My Sequel".

MySql

MYSQL:

MySql is used on web by a lot of websites, including high profile websites like Google, Facebook, Twitter , Flicker and Youtube. To use MySql we need to install an open source webserver package, preferably Xampp or Wamp. MySql comes as a component with both of these webserver packages. After installing the web server we need to start the apache and MySql services. To know more about installing a web server check this lesson:

How to install apache service to run php?

Now MySql services will be accessible to us in a web browser if we enter this url (http://localhost/phpmyadmin/). Executing (http://localhost/phpmyadmin/) in your web browser should take you to the phpMyAdmin page if it does not works as expected then there is something wrong in your web server configuration.

phpMyAdmin

phpMyAdmin:

phpMyAdmin is a free open source tool written in php for administration of MySql. The first and most important thing to do in phpMyAdmin is creating a database, then in second step create a table in the database and then fill the table by inserting data in it.

How to create a database in phpMyAdmin?

Creating a database in phpMyAdmin is very easy. To create a database click on the Databases tab in the top menu. You will see a screen like the one shown below:

Create Database

You can see an input field under the "Create database" text in the above image. Just type the name of the database you want to create and click the "Create" button. This will create a new database for you with the name you specified. Now in the second step we need to create a table in the database.

How to create a table in a database?

To create a table in a database select the database from the list by clicking the one you created as shown in the image below.

Select Database

You will be redirected to a page looking like the one shown below:

Create Table

Here you are required to specify the table name and the number of columns in the table (interger value) and click the "Go" button. For test purposes specify the number of columns equal to 3.

Create Table

Now it's time to specify the details of the 3 columns we created in our table. Right now the screen in front of you should look like this:

Specify Table Data

Let us specify the name of the first column as id and as an id should be an integer which is pre selected in the type so we will keep it that way. Now leave everything for this column the way things are and go to the drop down index and click it. You should see an option "PRIMARY", select this option and check the A_I box. That's it for this column, the index PRIMARY means that id is the primary key of this table and A_I means auto increment which means that each time a new record is inserted in this table the value of id will be auto incremented by 1 for the new record which will keep it unique for each record in the table. Now let us come to the second column, specify the name of the second column as "Name" and then click on the type drop down and select "VARCHAR" from the drop down as the data type. Now specify the "Length/Values" for this column equal to 50 as a name can not be longer than 50 characters. Now let us fill out the details for our third column. Specify the Name of the column as Email, Type as "VARCHAR" and "Length/Values" as 50. Now that we have filled the details of all the 3 rows, click on the "Save" button below to save the columns of the table.

Specify Table Data

How to insert data in a table?

After creating the table in the above step, now it's time to insert some records in the table. To insert data in the table click on the "Insert" tab in the above menu which will redirect you to a page looking like this one:

Insert Table Data

Leave the id field in the above image as it is because it is auto increment and fill out the Name and Email fields and click on the "Go" button below.

Insert Table Data

This will insert a record in your newly created table. Click on the "Browse" tab in the above menu to see the record.

Insert Table Data

Repeat the insertion process to insert more records in the table.

No comments:

Post a Comment