import pymysql
from pymysql.constants import CLIENT
conn = {
"host": "mysql_server_hostname",
"password": "my_password",
"port": <<port_no>>,
"user": "my_username",
"client_flag": CLIENT.MULTI_STATEMENTS
}
x = '\n'.join(open('file.sql', 'r').readlines())
with pymysql.connect(**conn) as cur:
cur.execute(x)