Mysql RELICATION对存过的处理是怎样的


本篇文章给大家分享的是有关Mysql RELICATION对存过的处理是怎样的,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。昨天鹰眼需求从一个大表(27G)删除47026788数据
用存储过程通过主键删除实现;用了1个小时50分钟;
QPS=47026788/(60*110)=7125.2709
这个速度已经满快了,都是随机读;[@more@]

当时我在想,MASTER用近两个小时,是不是SLAVE也用这么长时间么;到SLAVE一看,根本没有SQL在跑;
而且表里数据已经被清空;通过测试,我们发现MASTER在应用存过时,在BINLOG里记录的是真正最后执行的DML操作;
比如:
#101202 13:58:43 server id 2 end_log_pos 15842 Query thread_id=4058 exec_time=0 error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(‘v_entry_id’,238)
/*!*/;
# at 15842
#101202 13:58:43 server id 2 end_log_pos 15974 Query thread_id=4058 exec_time=0 error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(‘v_entry_id’,240)
/*!*/;
# at 15974
#101202 13:58:43 server id 2 end_log_pos 16106 Query thread_id=4058 exec_time=0 error_code=0
SET TIMESTAMP=1291269523/*!*/;
delete from test where id = NAME_CONST(‘v_entry_id’,242)
/*!*/;…所以只要MASTER执行完后,就会马上应用到SLAVE;
下面是一个删除数据的存储过程范例:
================================================
use test;
drop procedure if exists delete_expired;
delimiter //
CREATE PROCEDURE delete_expired(in in_date date)
BEGIN
declare done int default 0;
declare rowcnt int default 0 ;
declare v_entry_id int;
declare cur_del cursor For select id from test ;
DECLARE CONTINUE HANDLER FOR SQLSTATE ‘02000’ SET done = 1;
open cur_del;
start transaction;
cursor_loop:loop
fetch cur_del into v_entry_id;
if done=1 then leave cursor_loop ;
end if ;
delete fr开发云主机域名om test where id =v_entry_id;
set rowcnt=rowcnt+1;
if rowcnt=1000 then
set rowcnt =0 ;
commit;
start transaction;
end if ;
end loop cursor_loop ;
commit ;
close cur_del;
END ;//
DELIMITER ;

call delete_expired (‘2010-01-10’);
drop procedure if exists delete_expired ;
===========================================================以上就是Mysql RELICATION对存过的处理是怎样的,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注开发云行业资讯频道。

相关推荐: mysql的性能优化工具(源自韩锋大师,针对5.7修改)

点击(此处)折叠开发云主机域名或打开相关推荐: PHP Mysql support: 是mysql 还是mysqlnd?您正在使用其中一个备用存储库安装现代版本的php,突然间您遇到了一个令人困惑的选择。你想在php程序中支持mysql(mysqli或PDO-…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 06/28 08:37
下一篇 06/28 08:38

相关推荐