python中PyMySQL有什么用

Python (170) 2023-07-17 15:07:14

1、说明

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

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

2、实例

importpymysql
conn=pymysql.connect(host='127.0.0.1',user='root',passwd="xxx",db='mysql')
cur=conn.cursor()
cur.execute("SELECTHost,UserFROMuser")
forrincur:
print(r)
cur.close()
conn.close()

以上就是python中PyMySQL的作用,希望对大家有所帮助。

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

THE END

发表回复