首先下载pymysql包

pip install pymysql

完整案例

import pymysql

db = pymysql. pymysql.connect(host='127.01.01', port=3306, user='root', passwd='123', db='demo', charset='utf8')
cursor = db.cursor()#创建链接对象
sql = "select * from demo.test"
cursor.execute(sql)
data = cursor.fetchone()#获取执行结果
db.close()
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐