欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python導(dǎo)出mysql指定binlog文件實(shí)現(xiàn)demo

 更新時(shí)間:2023年12月07日 11:25:26   作者:qq58fdc80357c56  
這篇文章主要介紹了python導(dǎo)出mysql指定binlog文件實(shí)現(xiàn)demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

要求

要求本地有py環(huán)境和全局環(huán)境變量

先測試直接執(zhí)行binlog命令執(zhí)行命令

Windows 本地直接執(zhí)行命令

# E:\output>E:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysqlbinlog binglog文件地址
# --no-defaults 不限制編碼
# -h mysql鏈接地址
# -u mysql 鏈接名稱
# -p mysql 密碼
# -P3306 mysql 端口
# --read-from-remote-server  --raw  mysqlbinlog 命令的一個(gè)選項(xiàng),它指示 mysqlbinlog 從遠(yuǎn)程 MySQL 服務(wù)器讀取二進(jìn)制日志文件進(jìn)行解析。
# binlog.000003 文件地址
#命令如下
E:\output>E:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysqlbinlog --no-defaults -h 127.0.0.1 -u root -p -P3306 --read-from-remote-server --raw binlog.000003

代碼

import subprocess
def download_binlogs(host, user, password, port, start_binlog, end_binlog, output_path):
    try:
        for binlog_number in range(start_binlog, end_binlog + 1):
            binlog_filename = f"binlog.{str(binlog_number).zfill(6)}"
            output_filename = f"{output_path}/binlog_{binlog_number}.sql"
            # 構(gòu)建命令
            command = [
                'E:/phpstudy_pro/Extensions/MySQL5.7.26/bin/mysqlbinlog.exe',
                '--no-defaults',
                '-h', host,
                '-u', user,
                '-p' + password,
                '-P' + str(port),
                '--read-from-remote-server',
                '--raw',
                binlog_filename
            ]
            # 運(yùn)行命令并將輸出重定向到文件
            with open(output_filename, 'w') as output_file:
                subprocess.run(command, stdout=output_file)
                output_file.flush()  # 刷新緩沖區(qū)
            print(f"Binlog日志文件 '{binlog_filename}' 下載成功!保存為 '{output_filename}'")
    except Exception as e:
        print(f"下載失?。簕e}")
if __name__ == "__main__":
    # 替換以下信息為實(shí)際的Polardb連接信息和binlog文件范圍
    polardb_host = "127.0.0.1"
    polardb_user = "root"
    polardb_password = "root"
    polardb_port = 3306
    start_binlog_number = 1
    end_binlog_number = 3
    output_directory = "E:/output"  # 替換為你想要保存文件的目錄
    download_binlogs(polardb_host, polardb_user, polardb_password, polardb_port, start_binlog_number, end_binlog_number, output_directory)

python執(zhí)行

python .\binlog.py

以上就是python導(dǎo)出mysql指定binlog文件實(shí)現(xiàn)demo的詳細(xì)內(nèi)容,更多關(guān)于python導(dǎo)出mysql指定binlog文件 的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python函數(shù)使用的相關(guān)練習(xí)題分享

    Python函數(shù)使用的相關(guān)練習(xí)題分享

    這篇文章主要介紹了Python函數(shù)使用的相關(guān)練習(xí)題分享,文章基于python函數(shù)內(nèi)容展開其相關(guān)例題,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • Python?Watchdog實(shí)現(xiàn)實(shí)時(shí)監(jiān)控文件系統(tǒng)

    Python?Watchdog實(shí)現(xiàn)實(shí)時(shí)監(jiān)控文件系統(tǒng)

    Python?Watchdog是一個(gè)優(yōu)秀的第三方庫,用于實(shí)現(xiàn)高效的文件系統(tǒng)監(jiān)控,本文將為大家詳細(xì)介紹一下Python如何使用Watchdog實(shí)現(xiàn)實(shí)時(shí)監(jiān)控文件,需要的可以參考下
    2023-11-11
  • python中pop()函數(shù)的語法與實(shí)例

    python中pop()函數(shù)的語法與實(shí)例

    這篇文章主要給大家介紹了關(guān)于python中pop()函數(shù)語法與實(shí)例的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Python Flask的request對象使用詳解

    Python Flask的request對象使用詳解

    本文介紹Flask request對象,一個(gè)完整的HTTP請求,包括客戶端向服務(wù)端發(fā)送的Request請求和服務(wù)器端發(fā)送Response響應(yīng).為了能方便訪問獲取請求及響應(yīng)報(bào)文信息,Flask框架提供了一些內(nèi)建對象,下面就來說一下Flask針對請求提供內(nèi)建對象reques,需要的朋友可以參考一下
    2023-02-02
  • PyQt5的相對布局管理的實(shí)現(xiàn)

    PyQt5的相對布局管理的實(shí)現(xiàn)

    這篇文章主要介紹了PyQt5的相對布局管理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • 本機(jī)安裝PaddlePaddle安裝指南及步驟詳解

    本機(jī)安裝PaddlePaddle安裝指南及步驟詳解

    PaddlePaddle是百度研發(fā)的開源開放的深度學(xué)習(xí)平臺,有全面的官方支持的工業(yè)級應(yīng)用模型,涵蓋自然語言處理、計(jì)算機(jī)視覺、推薦引擎等多個(gè)領(lǐng)域,并開放多個(gè)領(lǐng)先的預(yù)訓(xùn)練中文模型。這篇文章主要介紹了本機(jī)安裝PaddlePaddle安裝指南,需要的朋友可以參考下
    2021-12-12
  • Pandas數(shù)據(jù)集的合并與連接merge()方法

    Pandas數(shù)據(jù)集的合并與連接merge()方法

    Pandas數(shù)據(jù)集的合并與連接(merge())是數(shù)據(jù)處理過程中常用的操作之一,在使用Pandas進(jìn)行數(shù)據(jù)集合并時(shí),可以使用merge()函數(shù)將兩個(gè)或多個(gè)數(shù)據(jù)集按照指定的列進(jìn)行合并,本文就來介紹一下,感興趣的可以了解一下
    2023-11-11
  • Python pandas.DataFrame 找出有空值的行

    Python pandas.DataFrame 找出有空值的行

    這篇文章主要介紹了Python pandas.DataFrame 找出有空值的行,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • python測試框架unittest和pytest區(qū)別

    python測試框架unittest和pytest區(qū)別

    這篇文章主要介紹了python測試框架unittest和pytest區(qū)別,幫助大家更好的理解和學(xué)習(xí)使用python進(jìn)行自動化測試,感興趣的朋友可以了解下
    2021-04-04
  • 寶塔部署django項(xiàng)目的實(shí)現(xiàn)步驟(圖文教程)

    寶塔部署django項(xiàng)目的實(shí)現(xiàn)步驟(圖文教程)

    本文主要介紹了寶塔部署django項(xiàng)目的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03

最新評論