首页 > 代码库 > mysql分表备份

mysql分表备份

#!/bin/sh

MYUSER=root

MYPASS=123123

MYSOCK=/tmp/mysql.sock

backup_path=/test

DBLIST="`mysql -u$MYUSER -p$MYPASS -e "show databases;" |grep -Ev ‘Database|mysql|schema‘`"

DUMP="mysqldump -u$MYUSER -p$MYPASS -F -R -x"

mkdir -p $backup_path

for db in $DBLIST

do

echo "db:"$db

TBLIST="$(mysql -u$MYUSER -p$MYPASS -e "show tables from $db;" |sed 1d)"

for tb in $TBLIST

do

$DUMP $db $tb |gzip >${backup_path}/mysqltest_${db}_${tb}_$(date +%F).sql.gz

echo "table:"$tb

done

done


本文出自 “神奇的海螺” 博客,谢绝转载!

mysql分表备份