Python连接SQL server和 MySQL(笔记)

python 连接SQL server 需要安装工具 pymssql

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)

python连接MySQL 也是最简单的

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)


你可能感兴趣的:(python,数据库mysql)