python中PyMySQL有什么用

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的作用,希望对大家有所帮助。更多Python学习指路:Python基础教程

发表回复