PyMySQL无法执行多个查询

问题描述 投票:0回答:1

使用最新版本的PyMySQL(0.9.3),我无法执行查询字符串,其中包含多个SQL语句,并用分号(;)分隔

我的python版本是:Python 3.6.5

import pymysql # version 0.9.3
conn = {
    "host": "mysql_server_hostname",
    "password": "my_password",
    "port": <<port_no>>,
    "user": "my_username"
}

my_query_str = 'show databases;use random_existing_db;'
with pymysql.connect(**conn):
    cur.execute(query)

错误返回:(1064,'在单个查询中检测到多个语句)

尝试使用PyMySQL-0.7.11运行相同的查询,并且有效

python python-3.x pymysql
1个回答
0
投票

在pymysql 0.8及更高版本中,默认情况下不再设置客户端标记。为了执行多个语句,需要通过client_flag = CLIENT.MULTI_STATEMENTS。

© www.soinside.com 2019 - 2024. All rights reserved.