Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export MySQL/MariaDB Database in Tables
Written on Debian Based Systems
usage: mysql_[import|export].sh DATABASENAME
Splits Database in to multplie files, based on Table Names
schema.sql will be also created!
Files: schema.sql
export/*.sql
#!/bin/bash
DATABASENAME=$1
if [ -z "$DATABASENAME" ]; then
echo "no database defined"
exit 1;
fi
LIST=$(mysql --defaults-file=/etc/mysql/debian.cnf $DATABASENAME -e "SHOW TABLES;" -N | xargs | sort)
mysqldump --defaults-file=/etc/mysql/debian.cnf --routines --no-data $DATABASENAME > schema.sql
rm -rf export
mkdir -p export
for t in $LIST; do
echo $t
mysqldump --defaults-file=/etc/mysql/debian.cnf --skip-triggers --no-create-info -e $DATABASENAME $t > export/${t}.sql
date
done
#!/bin/bash
DATABASENAME=$1
if [ -z "$DATABASENAME" ]; then
echo "no database defined"
exit 1;
fi
mysql --defaults-file=/etc/mysql/debian.cnf $DATABASENAME < schema.sql
date
for t in $(find export -iname "*.sql" -type f | sort); do
echo $(basename $t)
mysql --defaults-file=/etc/mysql/debian.cnf $DATABASENAME < $t
date
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment