집 >데이터 베이스 >MySQL 튜토리얼 >python3.4 使用pymysql 连接mysql数据库_MySQL
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