Cyberithub

How to Create Table in MySQL 5.5 with Easy Steps

Advertisements

In this article, we will go through the Steps to create table in MySQL 5.5 Database.

Here we will take a simple example where we will create a Database name Office and table Account, Employee and Department inside that. In the next article, i will populate values inside these tables and will go further deep inside the MySQL concepts.

What is MySQL

MySQL is an Open source relational database management system used mostly with the Linux Systems around the World. It supports most of DML and DDL Queries like select, delete, drop, create, delete etc.

How to Create Table in MySQL 5.5 with Easy Steps

Create Table in MySQL 5.5

We will first create a database name office which will house all of our tables.

Create Office Database

[root@localhost ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database office;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| office             |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.01 sec)

MariaDB [(none)]>

We need to use office database to create our tables.

MariaDB [(none)]> use office
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [office]>

Employee Table

We will create an Employee table with column Name ID, Phone and Address.

MariaDB [office]> create table Employee
-> (Name varchar(20),
-> ID int not null,
-> Phone int,
-> Address varchar(120)
-> );
Query OK, 0 rows affected (0.01 sec)

Account Table

Here we will create an Account table with column name ID, Name, Salary and Salary_date.

MariaDB [office]> create table Account
-> (ID int not null,
-> Name varchar(20),
-> Salary int,
-> Salary_date date
-> );
Query OK, 0 rows affected (0.00 sec)

Department Table

We will create a Department Table with Column ID, Dept_Name, Dept_Manager and Dept_Strength.

MariaDB [office]> create table Department
-> (ID int not null,
-> Dept_Name varchar(20),
-> Dept_Manager varchar(20),
-> Dept_Strength int
-> );
Query OK, 0 rows affected (0.01 sec)

Show all the tables in Office Database

MariaDB [office]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| Account        |
| Department     |
| Employee       |
+----------------+
3 rows in set (0.00 sec)

Also Read: How to install MySQL 5.5 DB

Reference: MySQL Documentation

Leave a Comment