码迷,mamicode.com
首页 > 数据库 > 详细

mysql分库.分表备份

时间:2015-05-27 19:26:59      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:mysql   table   databases   

1.mysql的分库备份

myuser=root

mypass=yzg1314520

mycmd="mysql -u$myuser -p$mypass "

mydump="mysqldump -u$myuser -p$mypass"


for database in  mysql test

do

        $mydump $database   > $database_$(date +%F).sql

       tar -zcvf $database_$(date +%F).tar.gz  $database_$(date +%F).sql

        rm -rf $database_$(date +%F).sql

done


2.mysql的分库分表备份

myuser=root

mypass=yzg1314520

mycmd="mysql -u$myuser -p$mypass "

mydump="mysqldump -u$myuser -p$mypass"


for database in  `$mycmd -e "show databases" | sed ‘1,3d‘`

do

        mkdir -p /home/scripts/mysqlbak

        for table in `$mycmd -e "show tables from $database;" |sed  ‘1d‘`

        do

        $mydump $database $table  > ${database}_${table}_$(date +%F).sql

         tar -zcvf ${database}_${table}_$(date +%F).tar.gz  ${database}_${table}_$(date +%F)

.sql

        mv ./${database}_${table}_$(date +%F).tar.gz  /home/scripts/mysqlbak

        rm -rf /home/scripts/${database}_${table}_$(date +%F).sql

        rm -rf  $(find /home/scripts/mysqlbak -name "*.tar.gz" -mtime +5 -type f)

        done

done


mysql分库.分表备份

标签:mysql   table   databases   

原文地址:http://yzg784534398.blog.51cto.com/9719002/1655677

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!