Home  >  Article  >  Database  >  python3.4 使用pymysql 连接mysql数据库_MySQL

python3.4 使用pymysql 连接mysql数据库_MySQL

WBOY
WBOYOriginal
2016-06-01 13:11:191653browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn