连接数据库
获取数据库连接
使用psycopg2.connect()获取连接:
conn = psycopg2.connect(database="postgres", user="vastbase", password="Aa@123456", host="127.0.0.1", port="5432")
关闭数据库连接
关闭连接时调用connect的close()方法即可:
conn = psycopg2.connect(database="postgres", user="vastbase", password="Aa@123456", host="127.0.0.1", port="5432")
conn.close()