Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-01 13:11:19
Original
1565 people have browsed it

python

系统是ubuntu14.04,安装pymysql非常简单

$ sudo pip3 install PyMySQL
Copy after login


用法也非常简单,一个简单的例子

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()
Copy after login

详细内容可以查看github:https://github.com/PyMySQL/PyMySQL

source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!