如果是操作 数据库 则需要按照第三方包
在cmd 中 录入
操作MySQL 需要安装的包
pip install pymysql操作 微软的 SQL Server 需要安装包
pip install pymssql
from pymysql import Connection
conn = Connection(
host="",
port=3306,
user='root',
password="",
autocommit=True # 自动确认 Insert
)
# 获取游标对象
cursor = conn.cursor()
# 选择数据库
conn.select_db("xx")
# 使用游标对象,执行SQL语句
cursor.execute(" sql segment")
# 如果insert 、update 等修改数据库的操作
# conn.commit()
# 获取查询结果
results: tuple = cursor.fetchall()
for r in results:
print(r)
# 关闭数据库连接
conn.close()