Export MySQL/MariaDB Database in Tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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