Welcome to MySQL Tutorial for Beginners part 4. Today we will create a database. And Create some Data.We are going to start using MySQL commands. Before we start we need to have some sort of Data.We are going to create some sample data. By now you should have required Software and Utilities for MySQL Installed on your PC. If not check earlier MySQL Tutorial for Beginners part 3.
Start MySQL Community Server,Toad or Sequel Pro on you computer. Then we are going to create a new connection to database server. Follow the steps below:
Connecting Toad to MySQL community server: For Toad go to File > New > Connection. Then you will see a new connection window like the picture below.
From the Connection Type select TCP. You can select connection type such as TCP, SSL, SSH, HTTP Tunnel . We will use TCP connection.
Here are the information to make new connection using Toad for MySQL.
Connection Type: TCP
Host : localhost
User : root
Password: Type in your Password
If you want to save the connection fill out the details at the bottom of the window.
Name: Anything you want (type IN)
Category: Select your Category
Then click the Save / Connect button. This new connection will be listed in the Connection Manager. After connecting go to Tools > Editor . We will write our Command in this editor.
If you are using MAC OS then you can use Sequel Pro as a alternative to Toad for MySQL. After Starting Sequel Pro you will see a window like the picture below:
Here are the information to make new connection using sequel pro:
Name: Type in Any Name
MySQL Host: localhost
password: Type in your password
Port: If any
Then Hit connect Button. Then click on Query to open the editor. Now we know where we going to spend our time. We are ready for Writing some MySQL Query. Here are some Rules to follow while writing MySQL Statements:
1.Reserved words should be uppercase.
2.A void using names like “CREATE”, “SHORT” and reserved words.
3. Any Object Name cannot start with space or End with Space.
4. If we want to create a table name Employee table and we write the name like : employeetable this word is pretty hard to read. But if we write emmployee_table then we can easily recognize this table.
Here we go…
CREATE DATABASE Statement In MySQL : We are going to Create a New Database Using the Editor. How to create Database in MySQL ? Just Type in
CREATE DATABASE Database Name;
For Our Tutorial We are going to use this :
CREATE DATABASE student;
Then Select all and Click on Execute Script On Toad This will create a database named student
Now Create a new Connection in Toad to Connect the Database named student.
After Connecting to the new Database are going to create a Table In MySQL Database.
How to create a Table In MySQL Database : We need to use CREATE TABLE statement to create a table in the Database student.
To create table we need to type in
CREATE TABLE table_name ( column_1 What type of data, column_2 What type of data, column_3 What type of data,...)
For Our Tutorial We are going to create a table name studenttb which have student_id, FirstName and LastName colums Here is a the query :
CREATE TABLE studenttb( student_id int(11) NOT NULL AUTO_INCREMENT, FirstName varchar(100) DEFAULT NULL, LastName varchar(100) DEFAULT NULL, PRIMARY KEY (`student_id`) )
Tags for the article:
- sql pro tutorial