python

系统是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

09-12 13:05