MySql backup & restore commands

This article has some handy commands to backup and restore mysql databases. Some of the terms used below refer to

USERNAME = your username
MYSQL_PASSWORD = your password
DATABASE_1 = name of the database
LOCAL_DOMAIN.COM = local domain name
DESTINATION_DOMAIN.COM = remote domain name

Take MySql dump, gzip it and take it in a directory.

 

Take MySql dump and place it with the current date in file name.

This command will take a mysql dump. It will then gzip the sql file and set to another server via ssh and take it in the requried directory.

unzip .sql.tar file

unzip .sql.gz file

Run a database backup

Backup a database via cronjob. This command will place the backups in a specific directory and also also remove backups which are more then 30 days old.

Moving all databases and exclude few databases like mysql, information_schema, performance_schema.

Import only one database from multiple database in a sql file