How to create a mysql database, table and insert content

How to create a mysql database, table and insert data in to it.

In this post i am going to explain how to create a mysql database, table and insert data in to the table. This is a very basic mysql task and every linux admin should know this task. Previously we have seen about how to dump and restore mysql database from command line.

 

How to create a mysql database, table and insert content

 

Step 1: First login to mysql command line.

If you don’t have password to login to mysql use the below command to login

#mysql

If you have set password to login to mysql use the below command to login

#mysql -p

Step 2: How to create a mysql database

To create a database in mysql use the below command inside the mysql command prompt.

Syntax:

#create database database_name ;

Example:

#create database linux ;

Use the below command to see all the databases.

#show databases ;

 

How to create a mysql database, table and insert conten

 

Step 3: Create tables inside the database

To create tables inside the database we need to enter in to the database first. To do so give the below command inside the mysql command line.

#use linux

To create a table use the below command inside mysql command line.

Syntax:
#create table [table_name] (column_name column_type);

Example:
create table Users (Localuser VARCHAR(20), Systemuser VARCHAR(20), Superuser VARCHAR(20));

 

How to create a mysql database, table and insert content

Step 4: Insert data or content in to the table.

Insert data or content in to the table is one of the prime task. To do that use the below way.

Syntax:

INSERT INTO table_name (column1, column2, column3,…) VALUES (value1, value2, value3,…) ;

Example:

INSERT INTO Users (Localuser,Systemuser,Superuser) VALUES (“Rajkumar”, “Mysql”, “Root”) ;

 

How to create a mysql database, table and insert content




Leave a Reply

Your email address will not be published. Required fields are marked *