pip install pymssql
直接展示案例:亲自测试过。
import pymssql
conn = pymssql.connect(
host="192.168.1.10\MSSQLSERVER1",
user="sa",
password="****",
database="NTD180912",
charset ="utf8",
as_dict=True
)
cursor = conn.cursor()
cursor.execute('SELECT * FROM TS_SysAppVersion')
row = cursor.fetchall()
print(row)
import pymysql
db = pymysql.connect(host="182.61.43.31", port=3306, user="admin", passwd="***", db="app-zb", charset="utf8mb4")
cursor = db.cursor()
cursor.execute("SELECT * FROM tyapp")
results = cursor.fetchall()
print(results)