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

安装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流程图如下:

猜你喜欢

转载自www.cnblogs.com/canglongdao/p/12093973.html