Reputation: 7768
I have a linux system with Mysql contain more than 400 databases,I need to export each databases as a single *.sql
file.Is it possible to do this with mysql_dump
or Mysqlworkbench
.
I have tried mysql_dump
with --all-databases
option.but this make a file with all database.it is large in size.
Upvotes: 0
Views: 828
Reputation: 2682
One way to achieve this is to write a bash script: (Source)
#! /bin/bash
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/backup/$TIMESTAMP"
MYSQL_USER="backup"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="password"
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p "$BACKUP_DIR/mysql"
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.gz"
done
For more information, have a look at this similar question.
Upvotes: 1