1、python连接pgsql
import psycopg2 def connect_pgsql(list_sql): conn = psycopg2.connect(host='db_host', user='db_user', password='db_passwd', database='db_name', port='db_port') cursor = conn.cursor() cursor.execute(list_sql) logger.info("执行sql语句: %s" % list_sql) conn.commit() cursor.close() conn.close()
2、Python连接mysql
import pymysql def connect_mysql(list_sql): conn = pymysql.connect(host='db_host', user='db_user', password='db_passwd', database='db_name', port='db_port') cursor = conn.cursor() cursor.execute(list_sql) logger.info("执行sql语句: %s" % list_sql) conn.commit() cursor.close() conn.close()
标签:cursor,python,list,mysql,db,pgsql,connect,sql,conn From: https://www.cnblogs.com/kobeBryant-8/p/17903283.html