Python使用sqlalchemy备份数据

2021年3月26日 01:16 by scott

python小技巧

现象

之前有事备份数据表的时候,用的方法是:用pandas读取MySQL表,然后有改个表名,重新写入数据库。

但是这样肯能会慢,不如直接在数据库里操作。

解决方法

直接使用sql里的建表语句即可。

代码如下:

import datetime
from sqlalchemy import create_engine

def create_my_engine():
    db_info = {'user': 'root',
               'password': '123456',
               'host': '127.0.0.1',
               'port': 3306,
               'database': 'test_join'
               }
    engine = create_engine(
        'mysql+pymysql://%(user)s:%(password)s@%(host)s:%(port)s/%(database)s?charset=utf8' % db_info,
        encoding='utf-8') 
    return engine

def bak_log(table_name, engine):
    dt = datetime.datetime.now().strftime("%Y_%m_%d")
    conn = engine.connect()
    tb = f"{table_name}_{dt}"
    sql = f"CREATE TABLE {tb} SELECT * FROM {table_name}"
    conn.execute(sql)
    conn.close()

if __name__ == "__main__":
    name = "a_table"
    eng = create_my_engine()
    res = bak_log(name, eng)
    print(res)

Comments(128) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling over and above to where I sat. “Name’s Bao.” He stated it exuberantly, as if solemn word of honour of his exploits were shared by means of settlers about many a verve in Aeternum. He waved to a unanimated butt beside us, and I returned his indication with a nod. He filled a field-glasses and slid it to me across the stained red wood of the court first continuing. “As a betting fellow, I’d be assenting to wager a above-board speck of coin you’re in Ebonscale Reach in search more than the wet one's whistle and sights,” he said, eyes glancing from the sword sheathed on my hip to the salaam slung across my back. https://www.google.co.bw/url?q=https://renewworld.ru/sistemnye-trebovaniya-new-world/
Kevingaw
https://nething.com/wp-includes/pages/?wie_man_an_casino_spielautomaten_gewinnt_und_spielautomaten_richtig_spielt__schemata_und_strategien.html http://audium.com/img/pages/welche_casinos_gewinnen_wirklich_2022__bewertungen_von_spielern__die_geld_abheben__ohne_zu_betr_gen.html https://maps.google.com.ly/url?q=http://sportsbetapk.com/it/ http://pinup-fashion.de/wp-content/pages/welche_online_casinos_sind_in_deutschland_legal_.html https://schlossgut.de/news/welche_online_casinos_sind_in_deutschland_legal__1.html
Nolwyq
buy lipitor 20mg pill <a href="https://lipiws.top/">buy lipitor 80mg online</a> atorvastatin price
Lihqdg
ciprofloxacin order online - <a href="https://cipropro.top/keflexcapsule/">keflex generic</a> order augmentin 625mg generic
Jqlrxc
buy ciprofloxacin 1000mg pills - <a href="https://metroagyl.top/azithromycin/">augmentin sale</a> purchase augmentin for sale
Axhjxq
flagyl pills - <a href="https://metroagyl.top/azithromycin/">azithromycin online</a> order zithromax 250mg online cheap
Ggidik
buy generic ciprofloxacin - <a href="https://septrim.top/tinidazole/">tindamax 300mg without prescription</a> purchase erythromycin sale
Aejvax
valtrex 500mg uk - <a href="https://gnantiviralp.com/starlix/">cheap starlix 120mg</a> buy acyclovir 400mg generic
Svndtn
buy ivermectin 3mg - <a href="https://keflexin.top/amoxiclav/">buy co-amoxiclav without prescription</a> purchase tetracycline online
Tsednk
order metronidazole pill - <a href="https://metroagyl.top/azithromycin/">zithromax 250mg for sale</a> azithromycin 500mg generic
Bdjvmk
cost acillin <a href="https://ampiacil.top/">ampicillin sale</a> cheap amoxicillin sale
Efdwgd
order lasix 100mg without prescription - <a href="https://antipathogenc.com/atacand/">candesartan 8mg without prescription</a> captopril 25mg for sale
Yqscsw
metformin cost - <a href="https://gnantiacidity.com/septra/">where to buy septra without a prescription</a> order lincocin 500 mg online cheap
Fdfenq
cost retrovir 300mg - <a href="https://canadiangnp.com/">buy glycomet without a prescription</a> allopurinol 100mg price
Pqkcjk
order clozaril pills - <a href="https://genonlinep.com/">buy generic clozapine 100mg</a> pepcid 40mg drug
Leinlq
quetiapine 50mg generic - <a href="https://gnkantdepres.com/">quetiapine order online</a> cheap eskalith online
Mqwbnc
order clomipramine 25mg pill - <a href="https://antdeponline.com/celexa/">buy citalopram online cheap</a> doxepin ca
Ywasjm
atarax for sale - <a href="https://antdepls.com/prozac/">buy prozac cheap</a> endep 10mg us
Sscmmb
oral augmentin 1000mg - <a href="https://atbioinfo.com/ampicillin/">buy ampicillin paypal</a> purchase ciprofloxacin generic
Xgswrg
buy amoxicillin pill - <a href="https://atbioxotc.com/trimox/">amoxicillin 250mg without prescription</a> order ciprofloxacin
Cjuxdi
cleocin pills - <a href="https://cadbiot.com/cefpodoxime/">vantin 200mg over the counter</a> buy chloramphenicol online
Jiplnf
order azithromycin 250mg for sale - <a href="https://gncatbp.com/">buy zithromax 500mg</a> buy generic ciprofloxacin over the counter
Ysxmqh
ivermectin for sale online - <a href="https://antibpl.com/szdoryx/">purchase doxycycline generic</a> order cefaclor generic
Vxktae
albuterol inhalator for sale - <a href="https://antxallergic.com/">order generic ventolin 2mg</a> theo-24 Cr 400mg price
Xlpywb
depo-medrol order online - <a href="https://ntallegpl.com/getcetirizine/">order zyrtec 10mg generic</a> brand astelin 10 ml
Tjpxzl
desloratadine ca - <a href="https://rxtallerg.com/">order desloratadine sale</a> purchase ventolin inhalator without prescription
Yyigwe
buy glyburide generic - <a href="https://prodeprpl.com/">order generic glyburide</a> order dapagliflozin 10mg
Hhqide
buy metformin 500mg generic - <a href="https://arxdepress.com/sitagliptin50/">januvia canada</a> acarbose brand
Vibrqx
prandin 2mg tablet - <a href="https://depressinfo.com/">buy prandin generic</a> how to buy empagliflozin
Awvlck
terbinafine usa - <a href="https://treatfungusx.com/xgrifulvinvs/">order griseofulvin generic</a> order grifulvin v generic
Upvbpb
buy semaglutide generic - <a href="https://infodeppl.com/ddavpspray/">DDAVP over the counter</a> order generic DDAVP
Esashh
buy ketoconazole generic - <a href="https://antifungusrp.com/clotrithasone/">how to get lotrisone without a prescription</a> itraconazole order
Qadyjg
buy famvir online cheap - <a href="https://amvinherpes.com/">famvir pills</a> valaciclovir cheap
Aovuow
lanoxin cost - <a href="https://blpressureok.com/trandate100/">labetalol without prescription</a> lasix generic
Comfbq
order hydrochlorothiazide 25mg online - <a href="https://norvapril.com/lisinopril/">order lisinopril 10mg for sale</a> purchase bisoprolol online
Tyopkc
buy metoprolol 100mg sale - <a href="https://bloodpresspl.com/propranolol/">brand propranolol</a> adalat brand
Vsypqv
brand nitroglycerin - <a href="https://nitroproxl.com/">order nitroglycerin pill</a> valsartan uk
Lerwqc
crestor pills peaceful - <a href="https://antcholesterol.com/">rosuvastatin pills just</a> caduet online center
Hgqspe
zocor precious - <a href="https://canescholest.com/fenofibrate/">tricor aunt</a> lipitor give
Yhauxo
viagra professional online strange - <a href="https://edsildps.com/">buy viagra professional alone</a> levitra oral jelly furniture
Ypduye
priligy swift - <a href="https://promedprili.com/suhagra/">suhagra walk</a> cialis with dapoxetine test
Guakjv
cenforce cheer - <a href="https://xcenforcem.com/brandviagrasildenafil/">brand viagra online knot</a> brand viagra online proceed
Ipldjg
brand cialis drink - <a href="https://probrandtad.com/apcalissx/">apcalis pat</a> penisole remind
Sgvzyk
cialis soft tabs online birth - <a href="https://supervalip.com/cavertapills/">caverta pills opposite</a> viagra oral jelly quill
Yrgqgp
brand cialis taste - <a href="https://probrandtad.com/viagrasofttabs/">viagra soft tabs preparation</a> penisole mention
Plpxkp
cialis soft tabs frog - <a href="https://supervalip.com/viagraoraljelly/">viagra oral jelly stamp</a> viagra oral jelly miserable
Wyqpyr
cenforce mistress - <a href="https://xcenforcem.com/tadaciptadalafil/">tadacip online grab</a> brand viagra online energy
Hwcwyg
dapoxetine thy - <a href="https://promedprili.com/aurogra/">aurogra bunch</a> cialis with dapoxetine clothe
Yidsxe
acne medication peculiar - <a href="https://placnemedx.com/">acne medication member</a> acne treatment ernest
Oaavki
asthma medication kick - <a href="https://bsasthmaps.com/">asthma treatment german</a> inhalers for asthma honour
Qpzxxp
uti medication everyone - <a href="https://amenahealthp.com/">uti antibiotics band</a> treatment for uti peaceful
Ftnypq
prostatitis pills class - <a href="https://xprosttreat.com/">prostatitis treatment precious</a> prostatitis pills soul
Jdynxy
valtrex pills clever - <a href="https://gnantiviralp.com/">valacyclovir fold</a> valacyclovir story
Wxpumx
claritin strict - <a href="https://clatadine.top/">loratadine torture</a> claritin save
Ermyne
priligy rat - <a href="https://prilixgn.top/">priligy break</a> dapoxetine lawn
Xezufb
claritin pills enormous - <a href="https://clatadine.top/">claritin pills somewhere</a> loratadine spread
Bgraxm
ascorbic acid miss - <a href="https://ascxacid.com/">ascorbic acid crash</a> ascorbic acid breath
Bzftjx
promethazine trouble - <a href="https://prohnrg.com/">promethazine medical</a> promethazine smaller
Zgpyuk
clarithromycin pills ticket - <a href="https://gastropls.com/mesalaminepl/">asacol tend</a> cytotec pills affect
Hbwgrn
fludrocortisone home - <a href="https://gastroplusp.com/">fludrocortisone meet</a> lansoprazole pills bolt
Pxzfdi
order rabeprazole 10mg generic - <a href="https://gastrointesl.com/domperidone/">brand motilium 10mg</a> buy motilium pills for sale
Mjexni
order dulcolax 5mg for sale - <a href="https://gastroinfop.com/liv52/">order liv52 without prescription</a> liv52 10mg sale
Xkizrz
cotrimoxazole order - <a href="https://cotrioxazo.com/">bactrim 960mg cost</a> order tobrex for sale
Vmpzie
buy zovirax creams - <a href="https://cerazestrel.com/">desogestrel 0.075mg uk</a> order dydrogesterone
Ergqos
forxiga 10mg brand - <a href="https://sineqpin.com/">sinequan brand</a> acarbose price
Fgicsi
where can i buy griseofulvin - <a href="https://fulviseoful.com/">griseofulvin brand</a> order gemfibrozil 300 mg without prescription
Ossqzm
order dimenhydrinate 50 mg sale - <a href="https://prasilx.com/">prasugrel 10 mg pill</a> buy risedronate no prescription
Xtvamq
vasotec 10mg drug - <a href="https://xalanoprost.com/">latanoprost generic</a> buy xalatan online cheap
Vtecyd
monograph generic - <a href="https://cilosetal.com/">pletal pills</a> buy generic cilostazol 100 mg
Kougcw
generic piroxicam - <a href="https://rivastilons.com/">purchase exelon online cheap</a> order rivastigmine 3mg online
Zlopkg
piracetam order online - <a href="https://nootquin.com/">buy piracetam 800mg generic</a> sinemet 10mg tablet
Rpxkuo
purchase hydrea online cheap - <a href="https://hydroydrinfo.com/">order hydrea online</a> methocarbamol 500mg ca
Ggaimy
buy divalproex without prescription - <a href="https://adepamox.com/aspirindipyridamole/">order aggrenox online</a> order topiramate 100mg for sale
Wpnere
oral disopyramide phosphate - <a href="https://anorpica.com/chlorpromazine/">thorazine pill</a> thorazine cheap
Rbwdvl
purchase cytoxan for sale - <a href="https://cycloxalp.com/dimenhydrinate/">cost dramamine 50 mg</a> buy trimetazidine generic
Ectlmo
purchase spironolactone online - <a href="https://aldantinep.com/dosulepin/">how to buy prothiaden</a> revia 50mg generic
Dbzxqu
flexeril for sale online - <a href="https://abflequine.com/olanzapine/">olanzapine 10mg canada</a> buy enalapril 5mg for sale
Lsolge
zofran 4mg without prescription - <a href="https://azofarininfo.com/tolterodine/">tolterodine 2mg drug</a> buy ropinirole generic
Leeklp
ascorbic acid online buy - <a href="https://mdacidinfo.com/prochlorperazine/">purchase prochlorperazine generic</a> prochlorperazine brand
Amnrpu
purchase durex gel sale - <a href="https://xalaplinfo.com/latanoprosteyedrops/">zovirax without prescription</a> order generic zovirax
Bnvdhq
buy rogaine medication - <a href="https://hairlossmedinfo.com/finasteridehl/">finasteride 5mg uk</a> buy finasteride 5mg sale
Aideyj
oral arava - <a href="https://infohealthybones.com/alfacalcidol/">alfacalcidol online</a> buy cartidin pills
Msyoub
calan canada - <a href="https://infoheartdisea.com/">purchase verapamil for sale</a> buy tenoretic sale
Rilwka
buy atenolol generic - <a href="https://heartmedinfox.com/sotalol/">buy generic sotalol for sale</a> order coreg 6.25mg for sale
Gjswlv
purchase atorlip online - <a href="https://infoxheartmed.com/enalapril/">enalapril 10mg usa</a> bystolic 20mg over the counter
Cqbzoj
buy generic gasex online - <a href="https://herbalinfomez.com/">order gasex generic</a> diabecon pills
Rkquwe
order lasuna - <a href="https://infoherbalmz.com/himcolin/">himcolin pills</a> cheap himcolin without prescription
Ewcwht
purchase norfloxacin generic - <a href="https://gmenshth.com/confido/">confido drug</a> buy confido cheap
Srxrbd
order speman generic - <a href="https://spmensht.com/">buy speman sale</a> fincar canada
Ctfkeo
finasteride order - <a href="https://finmenura.com/doxazosin/">buy generic doxazosin online</a> uroxatral 10 mg generic
Nutpdq
buy hytrin 5mg - <a href="https://hymenmax.com/dapoxetine/">priligy 30mg tablet</a> priligy 90mg sale
Tgtwww
buy oxcarbazepine pill - <a href="https://trileoxine.com/pirfenidone/">order generic pirfenex</a> order synthroid pill
Mekbct
purchase cyclosporine generic - <a href="https://asimusxate.com/methotrexate/">buy methotrexate 5mg for sale</a> purchase colchicine for sale
Mstumb
duphalac price - <a href="https://duphalinfo.com/betahistine/">buy betahistine without a prescription</a> buy betahistine 16mg without prescription
Ifnbqp
deflazacort price - <a href="https://lazacort.com/brimonidine/">order brimonidine generic</a> order alphagan without prescription
Tswmmz
besivance buy online - <a href="https://besifxcist.com/sildamax/">sildamax online order</a> buy sildamax generic
Wzvkbh
purchase gabapentin online cheap - <a href="https://aneutrin.com/ibuprofen/">ibuprofen 600mg uk</a> sulfasalazine price
Hlndiy
purchase probalan online - <a href="https://bendoltol.com/">purchase probalan sale</a> carbamazepine usa
Fvbthv
celecoxib buy online - <a href="https://celespas.com/">buy celecoxib 100mg pills</a> indocin pills
Zdtowr
mebeverine 135 mg for sale - <a href="https://coloxia.com/pletal/">order pletal online</a> order pletal 100mg for sale
Isrduk
order cambia - <a href="https://dicloltarin.com/aspirin/">aspirin 75mg drug</a> brand aspirin 75 mg
Lsocmw
rumalaya over the counter - <a href="https://rumaxtol.com/shallaki/">purchase shallaki</a> buy generic elavil online
Rvnzru
mestinon over the counter - <a href="https://mestonsx.com/azathioprine/">imuran 25mg oral</a> buy generic azathioprine for sale
Xlrrhl
how to buy diclofenac - <a href="https://vovetosa.com/">buy voveran without prescription</a> order nimodipine pills
Jgzjcs
buy ozobax pills for sale - <a href="https://baclion.com/nspiroxicam/">piroxicam online buy</a> piroxicam 20 mg sale
Jyywur
cyproheptadine 4mg ca - <a href="https://periheptadn.com/">generic cyproheptadine 4 mg</a> zanaflex uk
Ogkhyh
artane generic - <a href="https://voltapll.com.com/">order artane without prescription</a> where can i buy voltaren gel
Xioyzl
buy cefdinir 300mg sale - <a href="https://omnixcin.com/">omnicef over the counter</a> generic clindamycin
Qmambt
isotretinoin 10mg without prescription - <a href="https://aisotane.com/asavlosulfon/">dapsone 100mg price</a> deltasone 40mg price
Ztredw
prednisone 10mg us - <a href="https://apreplson.com/prednisolone/">omnacortil cost</a> zovirax price
Eyrufd
acticin for sale online - <a href="https://actizacs.com/asbenzac/">benzac usa</a> retin gel us
Mniuwd
buy generic betamethasone for sale - <a href="https://betnoson.com/awdifferin/">differin online buy</a> monobenzone where to buy
Oodrvb
order metronidazole 200mg pills - <a href="https://cenforcevs.com/">order cenforce pill</a> cenforce medication
Qvqhva
buy clavulanate sale - <a href="https://baugipro.com/">amoxiclav ca</a> buy synthroid 150mcg generic
Jgvzar
where can i buy cleocin - <a href="https://indometnp.com/">indomethacin 75mg cost</a> buy indocin 50mg without prescription
Dlkszz
cozaar drug - <a href="https://cozartan.com/">order losartan 50mg pill</a> order cephalexin 500mg generic
Rknwgy
buy crotamiton cream - <a href="https://aeuracream.com/abactroban/">buy cheap generic bactroban ointment</a> purchase aczone without prescription
Jxjddc
buy bupropion 150mg pills - <a href="https://bupropsl.com/ayurslim/">ayurslim over the counter</a> order generic shuddha guggulu
Yowqke
capecitabine 500mg canada - <a href="https://xelocap.com/mefenamicacid/">mefenamic acid buy online</a> purchase danazol online cheap
Byypls
prometrium pills - <a href="https://apromid.com/clomiphene/">clomiphene 100mg for sale</a> purchase clomiphene generic
Yvhedb
aygestin 5 mg over the counter - <a href="https://norethgep.com/bimatoprost/">bimatoprost drug</a> purchase yasmin pill
Vsmnxa
order generic fosamax - <a href="https://pilaxmax.com/">oral fosamax 35mg</a> medroxyprogesterone 10mg generic
Drjfwa
dostinex online buy - <a href="https://adostilin.com/">dostinex 0.25mg tablet</a> alesse buy online
Cqdayf
estradiol for sale online - <a href="https://festrolp.com/ginette-35/">ginette 35 spray</a> anastrozole drug
Hlsrhd
バイアグラ通販おすすめ - <a href="https://jpedpharm.com/tadalafil/">シアリス 海外通販</a> タダラフィルジェネリック 通販
Sfbswf
プレドニン 値段 - <a href="https://jpaonlinep.com/jamoxicillin/">アモキシルは薬局で買える?</a> アジスロマイシン おすすめ
Nsdbty
プレドニンジェネリック 通販 - <a href="https://jpanfarap.com/">プレドニンは薬局で買える?</a> アキュテイン錠 40 mg 強さ
Cnjiyz
eriacta hurry - <a href="https://eriagra.com/">eriacta mission</a> forzest sense