当前位置:首页 > 数据库 > 正文

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

2024-03-31 数据库

安装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))

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/13826.html