0

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.

kumarprd
  • 906
  • 2
  • 8
  • 21
Shijin TR
  • 7,516
  • 10
  • 55
  • 122
  • check this post may fix your issue: http://stackoverflow.com/questions/10867520/mysqldump-with-db-in-a-separate-file – kumarprd Jun 11 '15 at 08:53

1 Answers1

1

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.

Community
  • 1
  • 1
C_B
  • 2,620
  • 3
  • 23
  • 45