python 连接数据库
首先下载pymysql包pip install pymysql完整案例import pymysqldb = pymysql. pymysql.connect(host='127.01.01', port=3306, user='root', passwd='123', db='demo', charset='utf8')cursor = db.cursor()#创建链接对象sql = "selec
·
首先下载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()
更多推荐
已为社区贡献1条内容
所有评论(0)