Mysql Dump and Import
- Details
- Veröffentlicht: 19. September 2013
- Zugriffe: 12326
5.0 out of
5
based on
203 votes
there are 2 tool for dump and import on Linux Shell.
For export you can use:
mysqldump -u <USER> -p <Database> > <SafeFile>.dmp
This create a file whith the database structure.
For import you can use:
mysql -u <USER> -p <Database> < <SafeFile>.dmp
This create a Database whith the structure from the backup File.
If you want zip your export use:
mysqldump -u <USER> -p <Database> | gzip > <SafeFile>.dmp
If you want create daily a dump and remove old dumps after 14 days this script for bash can help:
#!/bin/bash
DATE=`date +%Y-%m-%d`
DATABASE=
USER=
PASS=
mysqldump -u $USER -p$PASS $DATABASE | gzip > /var/opt/mysqldump/daily-backup-$DATE.gz
find /var/opt/mysqldump -name "daily-backup-*" -atime +14 -exec rm {} \;