MagePsycho
8/4/2017 - 9:00 PM

MySQL: Dump all databases in a localhost

MySQL: Dump all databases in a localhost

#! /bin/bash

TIMESTAMP=$(date +"%F")
BACKUP_DIR="/home/rajendra"
MYSQL=/usr/bin/mysql
MYSQL_USER="root"
MYSQL_PASSWORD="mys123"
MYSQLDUMP=/usr/bin/mysqldump

mkdir -p "$BACKUP_DIR/mysql-dump"

databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`

for db in $databases; do
  $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.sql.gz"
done