当前位置:Gxlcms > 数据库问题 > python3连接数据库mysql,并进行查询

python3连接数据库mysql,并进行查询

时间:2021-07-01 10:21:17 帮助过:11人阅读

安装navicat for mysql,参考:https://www.jianshu.com/p/2494e02caf63

import pymysql
ecshop=pymysql.connect(‘localhost‘,‘root‘,‘root‘,‘ecshop‘) #连接数据库
cus=ecshop.cursor() #创建游标对象
cus.execute("SELECT VERSION()") #执行sql查询
#print(dir(cus))
datas=cus.fetchone() #获取单条数据
print(datas)
ecshop.close() #关闭数据库
#print(dir(ecshop))

python3连接数据库mysql,并进行查询

标签:mysq   tps   root   对象   游标   fetch   数据库   关闭   pre   

人气教程排行