python如何下载数据库
时间: 2023-03-24 22:03:58 浏览: 81
您可以使用Python的第三方库,如pymysql或psycopg2,来连接和操作数据库。您可以使用pip安装这些库,例如:
pip install pymysql
然后,您可以使用以下代码来连接MySQL数据库:
import pymysql
conn = pymysql.connect(
host='localhost',
user='root',
password='password',
db='database_name'
)
cursor = conn.cursor()
# 执行SQL查询
cursor.execute('SELECT * FROM table_name')
# 获取查询结果
result = cursor.fetchall()
# 关闭连接
conn.close()
类似地,您可以使用psycopg2来连接PostgreSQL数据库。
阅读全文
相关推荐








