python 连接数据库操作
pymysql
import pymysql
def get_connect():
connect = pymysql.connect(
host="xxx.com",
port=3306,
user="test",
password="test1234",
database="database_name",
charset="utf8mb4"
)
return connect
def execute_sql(sql):
connect = get_connect()
cursor = connect.cursor()
cursor.execute(sql) # 执行 sql
record = cursor.fetchone() # 查询记录
return record
if __name__ == '__main__':
print(execute_sql("select * from table_name"))
标签:__,execute,Python,数据库,pymysql,cursor,connect,sql,连接
From: https://www.cnblogs.com/abeelan/p/17203227.html