Database


Create


Syntax:

CREATE DATABASE  databasename;

Drop


Syntax:

DROP DATABASE  databasename;

Backup


Is used in SQL Server to create a full back up of an existing SQL database

BACKUP DATABASE databasename
TO DISK = 'filepath';

Differential

To only back up the parts of the database that have changed since the last full backup, use WITH DIFFERENTIAL

BACKUP DATABASE  databasename
TO DISK = 'filepath'
WITH  DIFFERENTIAL;

Dump > Backup

Using the CLI we can backup all the steps and data we need to recreated the db using SQL. This will include all the statements to create the exact db from scratch

  • Here below we have user = root
  • Password: if required
  • It will create a backup.sql file in the same directory where the db: employees is located
mysqldump -u root employees > employeesbackup.sql

Backup > Restore

Here using the same command in reverse would restore an entire db from the backup file

mysql --host=mysql -- port=3306 --user=root --password  employees < employeesbackup.sql

# from inside a mysql command prompt
mysql > source employeesbackup.sql