- CREATE DATABASE – create the database. To use this statement, you need the CREATE privilege for the database.
- CREATE TABLE – create the table. You must have the CREATE privilege for the table.
- INSERT – To add/insert data to table i.e. inserts new rows into an existing table.
Login as the mysql root user to create database:
mysql -u root -p
Create Database book
CREATE DATABASE books;
Select / Use Database for further operations
USE books;
Create a sample table in a database
CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
Check the table definition
SHOW TABLES;
Insert record in author table
INSERT INTO authors (id,name,email) VALUES(1,"Jig","xuz@abc.com");
INSERT INTO authors (id,name,email) VALUES(2,"Mak","m@gmail.com");
INSERT INTO authors (id,name,email) VALUES(3,"Hari","Hari@yahoo.com");
Select records from that table.
SELECT * FROM authors;