当前位置: 首页 > MySQL数据库

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

时间:2026-01-28 14:10:24

昨天鹰眼需求从一个大表(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 from 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中的varchar(N)
下一篇:mysqld got signal举例分析
mysql RELICATION
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素