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

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8158.html

(0)
上一篇 2021年7月18日 19:19
下一篇 2021年7月18日 19:19

相关推荐

发表回复

登录后才能评论