使用 MySQLdb 模块连接 MySQL
# coding=utf-8 #引入<a href="https://www.gaodaima.com/tag/mysql" title="查看更多关于mysql的文章" target="_blank">mysql</a> python客户端模块 import MySQLdb import sys #进行数据库连接 conn = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="pythontab", charset="utf8") <a href="https://www.gaodaima.com/tag/cursor" title="查看更多关于cursor的文章" target="_blank">cursor</a> = conn.cursor() #执行sql cursor.execute("select * from test") #列出数据 records = cursor.fetchall() for row in records: for r in row: print r
www#gaodaima.com来源gaodai^.ma#com搞#代!码网搞代码
来源:搞代码网:原文地址:https://www.gaodaima.com