0
点赞
收藏
分享

微信扫一扫

Python 3连接数据库


(一)安装pymysql

pip install

(二)查看版本号

import

# 打开数据库连接
db = pymysql.connect("localhost", "root", "123456", "test")

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()

print ("Database version : %s " % data)

# 关闭数据库连接
db.close()



举报

相关推荐

0 条评论