Sunday, September 22, 2013

backup and restore MySQL database

backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Dump only certain tables from a MySQL Database
mysqldump --user=XXXXXXXX --password=XXXXXXXX --databases DB_NAME --tables TABLE_NAME > /PATH/TO/DUMPFILE.SQL
on Heart server in /root/mysqltools i have some scripts:
to backup only one table run:
# ./one-table-dump.sh <dbname> <tablename>
#!/bin/bash
# one-table-dump.sh
/usr/bin/mysqldump --user=root --password=bigfoot123 --databases $1 --tables $2 | /bin/gzip -9 > $1.$2-/usr/bin/mysqldump --user=root --password=bigfoot123 --databases $1 --tables $2 | /bin/gzip -9 > $1.$2-`date +'%Y-%d-%m'`.gz

No comments:

Post a Comment