1

I have looked everywhere.. but not able to find any perfect solution (free) where I can download backup of all databases->tables individually so I can restore any table anytime I want and I do not have to restore whole database..

I am using mysql database, I have like 10-15 databases and 100+ tables in each.

I can see "Auto backup for mysql" does that. but its almost 100 bucks.. I want to know if I can do with terminal or any other tool.. I want to do backup everyday.. and want to have each table.sql file with the date and time..

Is it possible??

4

2 回答 2

1

利用mysqldump

你想要的一个例子

mysqldump --user=dbuser --password --tab=~/output/dir --all-databases

这将为用户已读取和锁定访问权限的所有数据库在 ~/output/dir 中放置一个单独的 sql 文件

在此处找到的完整命令列表

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

于 2013-08-05T20:21:07.297 回答
0

首先创建一个表列表

如果您正在处理所有数据库,请执行以下操作:

SQLSTMT="SELECT CONCAT(table_schema,'.',table_name)"
SQLSTMT="${SQLSTMT} FROM information_schema.tables WHERE table_schema NOT IN"
SQLSTMT="#{SQLSTMT} ('information_schema','mysql','performance_schema')"
mysql -h... -u... -p... -ANe"${SQLSTMT}" > /tmp/ListOfTables.txt

如果你只做一个特定的数据库(比如mydb),那么这样做:

SQLSTMT="SELECT CONCAT(table_schema,'.',table_name)"
SQLSTMT="${SQLSTMT} FROM information_schema.tables "
SQLSTMT="${SQLSTMT} WHERE table_schema='mydb'"
mysql -h... -u... -p... -ANe"${SQLSTMT}" > /tmp/ListOfTables.txt

然后以 10 个为一组转储所有表

TARGET_FOLDER=/backups/mysql
COMMIT_COUNT=0
COMMIT_LIMIT=10
for DBTB in `cat /tmp/ListOfTables.txt`
do
    DB=`echo ${DBTB} | sed 's/\./ /g' | awk '{print $1}'`
    TB=`echo ${DBTB} | sed 's/\./ /g' | awk '{print $2}'`
    BACKUP_FILE=${TARGET_FOLDER}/${DB}_${TB}.sql.gz
    MYSQLDUMP_OPTIONS="-h... -u... -p... --hex-blob --triggers"
    mysqldump ${MYSQLDUMP_OPTIONS} ${DB} ${TB} | gzip > ${BACKUP_FILE} &
    (( COMMIT_COUNT++ ))
    if [ ${COMMIT_COUNT} -eq ${COMMIT_LIMIT} ]
    then
        COMMIT_COUNT=0
        wait
    fi
done
if [ ${COMMIT_COUNT} -gt 0 ]
then
    wait
fi

试试看 !!!

于 2013-08-05T20:24:36.813 回答