找回密码
 立即注册

python链接mysql查询数据实例

2022-3-2 15:04| 发布者: 笨鸟编程| 查看: 1350| 评论: 0

摘要: 使用 MySQLdb 模块连接 MySQL # coding=utf-8 #引入mysql python客户端模块 import MySQLdb import sys #进行数据库连接 conn= MySQLdb.connect(host="localhost", user="root", passwd="123456", db="pythontab", ...
使用 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 rowin records:
    for rin row:
        print r

Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )

GMT+8, 2025-9-17 18:10 , Processed in 0.021880 second(s), 18 queries .

© 2001-2020

返回顶部