如何使用python中的单个查询更新MySQL数据库

时间:2019-02-01 09:11:00

标签: python mysql mysql-connector-python

我正在尝试使用cursor.executemany()更新数据库,但它只是在从数组读取数据时发送多个查询。是否有任何MySQL命令或MySQL Join命令可以使它成为一个查询?

update_list = [('iframe', 84.16, 'happybizpromo.com', 
'https://archivepoisk.info/i.js'), ('iframe/popups', 99.92, 
'http://v1hcmqbaqw.ru/d6safundjenk6af/14945.js', 
'https://owlfoccfmz9g.ru/d6safundjenk6af/26698.js'), ('iframe/popups', 
99.92, 'http://v1hcmqbaqw.ru/d6safundjenk6af/14945.js', 
'https://ge9v3xlg5h8.ru/d6safundjenk6af/24108/c/6a616272612e7275_0.js'), 
('lnkr_urlvalidation', 100.0, 'caplinkff.com', 
'https://extnotecat.com/addons/lnkr30_nt.min.js'), ('lnkr_urlvalidation', 
100.0, 'caplinkff.com', 'https://untsorce.cool/addons/lnkr30_nt.min.js'), 
('lnkr_urlvalidation', 100.0, 'lowffdompro.com', 
'http://appmakedev.xyz/addons/lnkr5.min.js'), ('lnkr_urlvalidation', 100.0,         
'lowffdompro.com', 'https://linkappdev.com/addons/lnkr27.min.js'), 
('lnkr_urlvalidation', 100.0, 'caplinkff.com', 
'http://comtakelink.xyz/addons/lnkr30_nt.min.js'), ('lnkr_urlvalidation', 
100.0, 'caplinkff.com', 'https://extcoolmake.xyz/addons/lnkr30_nt.min.js'), 
('urlvalidation', 97.1, 'https://linkcount.cool/1eaefda9f709934a5d.js', 
'http://henamecool.xyz/da5f9d1289ec612235.js'), ('iframe/popups', 100.0, 
'3pji3fx5q0bxl.ru','https://ca6pb5nop8lt.ru/d6safundjenk6af/27981/c/6e6f766963612e636f6d_0.js')]

my_cursor2.executemany("""
                            UPDATE unknown_scripts SET type=%s , 
match_percent=%s , matched_with=%s WHERE code=%s;
                            """,update_list)
virus_database.commit()
virus_database.close() 

1 个答案:

答案 0 :(得分:0)

您不能使用SQL用不同的值更新多行。这是不可能的。