PyMySQL unable to execute multiple queries PyMySQL unable to execute multiple queries python-3.x python-3.x

PyMySQL unable to execute multiple queries


In pymysql version 0.8 onwards client flag is no longer set by default. For executing multiple statements one needs to passclient_flag=CLIENT.MULTI_STATEMENTS.

reference: https://github.com/PyMySQL/PyMySQL/blob/v0.9.3/CHANGELOG#L66

Example of the fix below.

import pymysqlfrom pymysql.constants import CLIENTconn = {    "host": "mysql_server_hostname",    "password": "my_password",    "port": <<port_no>>,    "user": "my_username",    "client_flag": CLIENT.MULTI_STATEMENTS}my_query_str = 'show databases;use random_existing_db;'with pymysql.connect(**conn) as cur:    cur.execute(my_query_str)


That's right, I used the client_flag = CLIENT.MULTI_STATEMENTS parameter to take effect.