时间:2021-07-01 10:21:17 帮助过:41人阅读
系统是ubuntu14.04,安装pymysql非常简单
$ sudo pip3 install PyMySQL
用法也非常简单,一个简单的例子
import pymysqlconn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='mysql',charset="utf8"))#需加入charset="utf8",否则出现中文乱码cur = conn.cursor()cur.execute("SELECT Host,User FROM user") print(cur.description)print()for row in cur: print(row) cur.close() conn.close()
详细内容可以查看github:https://github.com/PyMySQL/PyMySQL