阅读更多
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