zoukankan      html  css  js  c++  java
  • pymysql同时执行多条语句时报错

    1. 我的脚本

    import pymysql
    
    
    sql = """
    update BaseInfo_dailyinfo_temp set open=26.88,close=32.86,high=32.86,low=26.88,exchange_rate=21.83,data_date='2021-07-05',exchange_amount=715182688.0,
    exchange_quantity=231947,price_change_amount=5.48,price_change_rate=20.01,update_time='2021-07-05 15:37:34' where code_id=1234;
    update BaseInfo_dailyinfo_temp set open=19.11,close=21.6,high=21.6,low=18.51,exchange_rate=26.22,data_date='2021-07-05',exchange_amount=1309556816.0,
    exchange_quantity=655858,price_change_amount=3.6,price_change_rate=20.0,update_time='2021-07-05 15:37:34' where code_id=352;
    """ conn = pymysql.Connect(user='root', password='123', host='127.0.0.1', db='stockAnalysis', port=3306) cur = conn.cursor() cur.execute(sql) conn.commit()

    2. 报错截图

    1. 

    3. 原因及解决方法

    1. pymysql在0.8版本以前(不包含0.8)是默认可以同时执行多条sql语句的,但是在0.8之后不再设置为默认,需要手动配置
    2. 配置方法是在获取数据连接时,配置参数
    client_flag=CLIENT.MULTI_STATEMENTS

    4. 更改后的代码

    import pymysql
    -- 导入模块
    from pymysql.constants import CLIENT sql = """ update BaseInfo_dailyinfo_temp set open=26.88,close=32.86,high=32.86,low=26.88,exchange_rate=21.83,data_date='2021-07-05',exchange_amount=715182688.0, exchange_quantity=231947,price_change_amount=5.48,price_change_rate=20.01,update_time='2021-07-05 15:37:34' where code_id=1234; update BaseInfo_dailyinfo_temp set open=19.11,close=21.6,high=21.6,low=18.51,exchange_rate=26.22,data_date='2021-07-05',exchange_amount=1309556816.0, exchange_quantity=655858,price_change_amount=3.6,price_change_rate=20.0,update_time='2021-07-05 15:37:34' where code_id=352;""" conn = pymysql.Connect(user='root', password='123', host='127.0.0.1', db='stockAnalysis', port=3306, client_flag=CLIENT.MULTI_STATEMENTS) # 添加client_flag参数
    cur = conn.cursor() cur.execute(sql) conn.commit()

     参考地址:https://stackoverflow.com/questions/58544640/pymysql-unable-to-execute-multiple-queries

  • 相关阅读:
    CodeForces 681D Gifts by the List (树上DFS)
    UVa 12342 Tax Calculator (水题,纳税)
    CodeForces 681C Heap Operations (模拟题,优先队列)
    CodeForces 682C Alyona and the Tree (树上DFS)
    CodeForces 682B Alyona and Mex (题意水题)
    CodeForces 682A Alyona and Numbers (水题,数学)
    Virtualizing memory type
    页面跳转
    PHP Misc. 函数
    PHP 5 Math 函数
  • 原文地址:https://www.cnblogs.com/JackShi/p/14973451.html
Copyright © 2011-2022 走看看