zoukankan      html  css  js  c++  java
  • MySQL--Skip GTID CAP

    import os
    
    script_file = "./skip_file.sql"
    
    
    def write_script(script_content):
        file_handle = open(script_file, 'a+')
        file_handle.writelines(script_content + "
    ")
        file_handle.close()
    
    
    def delete_script_file():
        if os.path.exists(script_file):
            os.remove(script_file)
    
    
    def get_skip_script_list(master_uuid, start_tran_id, end_tran_id):
        script_list = []
        current_tran_id = start_tran_id
        while current_tran_id <= end_tran_id:
            current_script = """
    SET @@SESSION.GTID_NEXT= '{master_uuid}:{tran_id}';
    BEGIN; COMMIT;
    """.format(
                master_uuid=master_uuid,
                tran_id=current_tran_id
            )
            current_tran_id = current_tran_id + 1
            script_list.append(current_script)
        script_list.append("SET SESSION GTID_NEXT = AUTOMATIC;")
        return script_list
    
    
    def main():
        master_uuid = "0275e614-b4b1-11e7-8f24-b8ca3a6fcb25"
        start_tran_id = 1
        end_tran_id = 177
        script_list = get_skip_script_list(master_uuid, start_tran_id, end_tran_id)
        write_script("
    ".join(script_list))
    
    
    if __name__ == '__main__':
        main()
    

    当从库误执行一些SQL时或其他原因导致主从上的gtid集合不一致时,可以通过这种方式生成一些空事务,避免主从切换后发生从库无法获取新主库已purge掉的binlog而中断。

  • 相关阅读:
    项目进展1
    团队项目(百药食坊)介绍
    结对编程—黄金点游戏(庞思瑶&季远琦)
    WC项目
    四则运算
    Week3——Session
    Spring IOC (DI-依赖注入)
    Week2——XML
    Week2——提交表单后后台的工作
    Week1——JavaEE
  • 原文地址:https://www.cnblogs.com/TeyGao/p/9288174.html
Copyright © 2011-2022 走看看