基础操作
import pymysqlconfig = {"host": "10.xx.xx.xx.xx","user": "root","password": "xxxxx","database": "xxxxx"}db = pymysql.connect(**config)sql = """select 'hello world'"""def execute_sql(sql):cursor = db.cursor()db.begin()try:cursor.execute(sql)response = cursor.fetchall()print(response)except Exception as e:print(e)db.rollback()else:db.commit()finally:cursor.close()db.close()execute_sql(sql)
