这篇文章主要介绍“MySQL怎么实现分库分表备份”,在日常操作中,相信很多人在MySQL怎么实现分库分表备份问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MySQL怎么实现分库分表备份”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
[root@db02 scripts]# cat /server/scripts/Store_backup.sh #!/bin/sh MYUSER=root MYPASS=xuliangwei SOCKET=/data/3306/mysql.sock MYLOGIN=”mysql -u$MYUSER -p$MYPASS -S $SOCKET” MYDUMP=”mysqldump -u$MYUSER -p$MYPASS -S$SOCKET -B” DATABASE=”$($MYLOGIN -e “show databases;”|egrep -vi “Data|_schema|mysql”)” for dbname in $DATABASE do MYDIR=/server/backup/$dbname [ ! -d $MYDIR ] && mkdir -p $MYDIR $MYDUMP $dbname|gzip >$MYDIR/${dbname}_$(date +%F).sql.gz done
[root@db02 /]# tree /server/backup/ /server/backup/ ├── oldboy26 │ ├──oldboy26_2015-12-29.sql.gz │ ├──oldboy26_2015-12-30.sql.gz │ └──oldboy26_2015-12-31.sql.gz ├── oldboy_xuliangwei26 │ ├──oldboy_xuliangwei26_2015-12-29.sql.gz │ ├──oldboy_xuliangwei26_2015-12-30.sql.gz │ └──oldboy_xuliangwei26_2015-12-31.sql.gz └── xuliangwei26 ├──xuliangwei26_2015-12-29.sql.gz ├──xuliangwei26_2015-12-30.sql.gz └── xuliangwei26_2015-12-31.sql.gz 3 directories, 9 files
[root@db02 scripts]# cat mysql_table.sh # #!/bin/sh USER=root PASSWD=xuliangwei SOCKET=/data/3306/mysql.sock MYLOGIN=”mysql -u$USER -p$PASSWD -S$SOCKET” MYDUMP=”mysqldump -u$USER -p$PASSWD -S$SOCKET” DATEBASE=”$($MYLOGIN -e “show databases;”|egrep -vi “Data|_schema|mysql”)” for dbname in $DATEBASE do TABLE=”$($MYLOGIN -e “use $dbname;show tables;”|sed ‘1d’)” for tname in $TABLE do MYDIR=/server/backup/$dbname/${dbname}_$(date +%F) [ ! -d $MYDIR ] && mkdir -p $MYDIR $MYDUMP $dbname $tname |gzip >$MYDIR/${dbname}_${tname}_$(date +%F).sql.gz done done
[root@db02 scripts]# tree /server/backup/ /server/backup/ ├── oldboy26 │ ├──oldboy26_2015-12-30 │ │├──oldboy26_oldboy_test_2015-12-30.sql.gz │ │└──oldboy26_oldboy_test2_2015-12-30.sql.gz │ └──oldboy26_2015-12-31 │ ├── oldboy26_oldboy_test_2015-12-31.sql.gz │ └── oldboy26_oldboy_test2_2015-12-31.sql.gz ├── oldboy_xuliangwei26 │ ├──oldboy_xuliangwei26_2015-12-30 │ │├──oldboy_xuliangwei26_cloudstack_2015-12-30.sql.gz │ │├──oldboy_xuliangwei26_dashborad_2015-12-30.sql.gz │ │└── oldboy_xuliangwei26_student_2015-12-30.sql.gz │ └──oldboy_xuliangwei26_2015-12-31 │ ├──oldboy_xuliangwei26_cloudstack_2015-12-31.sql.gz │ ├──oldboy_xuliangwei26_dashborad_2015-12-31.sql.gz │ └──oldboy_xuliangwei26_student_2015-12-31.sql.gz └── xuliangwei26 ├──xuliangwei26_2015-12-30 │├──xuliangwei26_openstack_2015-12-30.sql.gz │├──xuliangwei26_saltstack_2015-12-30.sql.gz │├──xuliangwei26_server_2015-12-30.sql.gz │└──xuliangwei26_zabbix_2015-12-30.sql.gz └──xuliangwei26_2015-12-31 ├──xuliangwei26_openstack_2015-12-31.sql.gz ├──xuliangwei26_saltstack_2015-12-31.sql.gz ├──xuliangwei26_server_2015-12-31.sql.gz └──xuliangwei26_zabbix_2015-12-31.sql.gz 9 directories, 18 files
到此,关于“MySQL怎么实现分库分表备份”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。