python连接mysql查询数据示例

2015-11-12 0 291
python连接mysql查询数据示例

使用 MySQLdb 模块连接 MySQL

# coding=utf-8
  
#引入mysql python客户端模块
import MySQLdb
import sys
#进行数据库连接
conn = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="pythontab", charset="utf8")
cursor = conn.cursor()
#执行sql
cursor.execute("select * from test")
#列出数据
records = cursor.fetchall()
for row in records:
    for r in row:
        print r

遇见资源网 python python连接mysql查询数据示例 http://www.ox520.com/15946.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务