Mysql Database Backup and Dump

本文介绍如何使用MySQL存储过程和AWS RDS特性来解决副本错误,并演示了删除历史数据表中指定时间范围内的记录的方法。同时,提供了备份表文件到S3存储桶的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mysql Database Backup and Dump

Fix the replica error on the slave for RDS on AWS
>CALL mysql.rds_skip_repl_error;

For clean one huge history table.

I am doing
>delete from table_name where click_time >= ‘2015-12’;

3 days we have about 1 million records in this table. And this huge query block the MySQL resources even we run this query in the back.

>mysql -uroot -ppassword -h127.0.0.1 -P3306 databasename -e "optimize table clicks_history_2016_12;" > /tmp/optimize_table.log &

Back up the table file in s3

>sudo tar zcf tablename.tar.gz tablename.*
>aws s3 cp --content-encoding gzip tablename.tar.gz s3://production/db_backups/db_2016_12_14/tablename.tar.gz

We learned MySQL store procedure recently, so we use this to delete the data day by day

drop procedure delete_data;

delimiter #
create procedure delete_data(IN v_max INT)
begin

declare v_counter int unsigned default 0;
while v_counter < v_max do
delete from click_history_2016_12 where click_time >= DATE(NOW()) - INTERVAL v_counter DAY;
select sleep(1);
set v_counter=v_counter+1;
end while;

end #
delimiter ;

delete 80 days data.
>mysql -uroot -ppassword -h127.0.0.1 -P3306 databasename -e "call delete_data(80);" > /tmp/procedure_delete.log &

References:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql_rds_skip_repl_error.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值