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.
Step 1: First login to mysql command line.
If you don’t have password to login to mysql use the below command to login
If you have set password to login to mysql use the below command to login
Step 2: How to create a mysql database
To create a database in mysql use the below command inside the mysql command prompt.
#create database database_name ;
#create database linux ;
Use the below command to see all the databases.
#show databases ;
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.
To create a table use the below command inside mysql command line.
#create table [table_name] (column_name column_type);
create table Users (Localuser VARCHAR(20), Systemuser VARCHAR(20), Superuser VARCHAR(20));
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.
INSERT INTO table_name (column1, column2, column3,…) VALUES (value1, value2, value3,…) ;
INSERT INTO Users (Localuser,Systemuser,Superuser) VALUES (“Rajkumar”, “Mysql”, “Root”) ;