To dump specific table(s):
mysqldump --add-drop-table -u user -pPASSWORD dbfoo table1 table2 > dump_foo
If you want to import a dump made with mysql 5 into mysql 4 you should pass the following parameters to mysqldump:
mysqldump --add-drop-table --compatible=mysql4 -u user -pPASSWORD dbfoo table1 table2 > dump_foo
Import the dump:
mysql -u USER -pPASSWORD dbfoo < dump_foo
If the dump is compressed with bzip2 then the following would work:
bzcat dump_foo.bz2 | mysql -u USER -pPASSWORD dbfoo
The purpose of this script is to drop a development testdatabase and load some data from production to play with.
#!/bin/bash # replace local DB with a fresh dump of remote DB # DANGEROUS - think twice before doing this! DEST=/tmp ssh root@host.tld "mysqldump -ppassword dbname table1 table2" > $DEST/dbname.dump if [ -e $DEST/dbname.dump ]; then echo "drop database dbname_dev; create database dbname_dev" | mysql # import cat $DEST/dbname.dump | mysql dbname_dev rm $DEST/dbname.dump fi
#!/bin/bash # Login MYSQLPW="password"; MYSQLUSER=root; MYSQLHOST=192.168.0.10; # read database names declare -a DATABASES; DATABASES=( $(mysql -h $MYSQLHOST -u $MYSQLUSER -p$MYSQLPW -Bse 'show databases') ) DATABASE_EXCLUDES=( db1 db2 ); # where do we save the dumps? str_BACKUPDEST=/var/backup/mysql; # remove excluded databases from backupset index=0; for i in ${DATABASES[*]}; do # in excludes list? for e in ${DATABASE_EXCLUDES[*]}; do if [ $e == $i ]; then # kick it! unset DATABASES[$index]; fi done ((index++)); done # now do the backup # uncomment to see what databases will be backed up: # echo ${DATABASES[@]}; for i in ${DATABASES[*]}; do # move the last dump to *.dump.old.bz2 if test -e ${str_BACKUPDEST}/${i}.dump.bz2; then mv ${str_BACKUPDEST}/${i}.dump.bz2 ${str_BACKUPDEST}/${i}.dump.old.bz2; fi mysqldump -h ${MYSQLHOST} -u ${MYSQLUSER} -p${MYSQLPW} $i > ${str_BACKUPDEST}/"${i}.dump"; # compress the dump to save space, fire bzip2 into backgroud, and continue immediately with mysqldump # with a handful of medium sized databases and a multi core CPU this will speed up things bzip2 ${str_BACKUPDEST}/"${i}.dump" & done