Create, Backup, Delete and Restore a simple database SQL

Posted by Samath
  1476
December 25, 2014

 

Hello World! Today I am going to show you how to create, backup, delete and restore a simple database. 

Create a database called SCHOOL and Create a Table in the SCHOOL database called Student.

Create Database SCHOOL;

USE SCHOOL;

CREATE TABLE Student(id INT NOT null primary key auto_increment, FirstName varchar(35),
LastName varchar(35), gpa FLOAT, DateofBirth varchar(35));

 

Insert Data into the Student database.

INSERT INTO Student(FirstName, LastName, gpa, DateofBirth) values ('John', 'Brown',3.75,'August 9 1978');
INSERT INTO Student(FirstName, LastName, gpa, DateofBirth) values ('Paul', 'Smith',3.87,'May 1 1978');
INSERT INTO Student(FirstName, LastName, gpa, DateofBirth) values ('Oprah', 'James',3.13,'June 8 1978');

 

Backup the database

mysqldump -u root -p SCHOOL >"C:\newSchoolDatabase.sql"

 

Delete the Student Database

DROP DATABASE SCHOOL;

 

Restore the SCHOOL database. 

mysql -u root -p SCHOOL <"C:\newSchoolDatabaseBackup.sql"