首页 > 文章列表 > python中PyMySQL有什么用

python中PyMySQL有什么用

Python PyMySQL
160 2022-08-07

1、说明

PyMySQL是纯Python实现的驱动,速度上比不上 MySQLdb,特点可能就是它的安装方式没那么繁琐,同时也兼容MySQL-python。

pip install PyMySQL
# 为了兼容mysqldb,只需要加入
pymysql.install_as_MySQLdb()

2、实例

import pymysql
conn = pymysql.connect(host='127.0.0.1', user='root', passwd="xxx", db='mysql')
cur = conn.cursor()
cur.execute("SELECT Host,User FROM user")
for r in cur:
    print(r)
cur.close()
conn.close()

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。