mysql5.6 分表分库脚本
[backcolor=inherit]Mysql基于mysqldump的分库备份脚本
#!/bin/bash
db_user='root'
db_passwd=123456
db_host=192.168.2.88
db_none="information_schema|mysql|performance_schema"
db_command=`mysql -u$db_user -p$db_passwd -h $db_host -e "show databases;" |sed '1d' |egrep -v $db_none`
db_dump="mysqldump -u$db_user -p$db_passwd -h $db_host --master-data=2 --flush-logs --lock-all-tables"
db_file='/mydata/mysqlbak'
if [ ! -d $db_file ];then
mkdir -p $db_file
fi
for i in $db_command;
do
$db_dump $i |gzip > $db_file/${i}_$(date +%F-%H-%M-%S).sql.gz
done
(注意:db_passwd db_host 是远程授权过的账号和密码 估计要有复制权限 replication slave)
Mysql基于mysqldump的分表备份脚本
#!/bin/bash
db_user=root
db_passwd=123456
db_host=192.168.2.8
db_none="information_schema|mysql|performance_schema"
db_connect="mysql -u$db_user -p$db_passwd -h $db_host"
db_command=`mysql -u$db_user -p$db_passwd -h $db_host -e "show databases;" |sed '1d' |egrep -v $db_none`
db_dump="mysqldump -u$db_user -p$db_passwd -h $db_host --master-data=2 --flush-logs --lock-all-tables"
db_file='/mydata/mysqlbak'
if [ ! -d $db_file ];then
mkdir -p $db_file
fi
for db in $db_command
do
if [ ! -d $db_file/$db ];the
mkdir -p $db_file/$db
fi
for table in `$db_connect -e "show tables from $db;"|sed '1d'`
do
$db_dump $db $table |gzip > $db_file/${db}/${table}_$(date +%F-%H-%M-%S).sql.gz
done
done