py学习笔记:python3.4连接mysql数据库

下载第三方mysql库

http://yunpan.cn/QC2gemBIcUvui  访问密码 07cf

解压到某个文件夹下,通过dos进入文件夹,并输入 python setup.py install进行安装

coding=utf-8 #author = 'pengwei' #导入mysql库 import pymysql #连接数据库 db = pymysql.connect(host="localhost", user="root", passwd="wei8888go", db="score", charset='utf8') cursor = db.cursor() cursor.execute("SELECT * FROM users") result = cursor.fetchall() for record in result: power='%d' %record[2] print("name:"+record[0]+",pwd:"+record[1]+",power:"+power)

power列在数据库中是int型,所以通过‘%d’ %record[2]转化为字符型