python链接mysql查询数据

使用 MySQLdb 模块连接 MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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 rowin records:
    for rin row:
        print r
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容