#!/usr/bin/python
# -*- coding: utf8 -*-
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="phpcool",db="device")
cursor=conn.cursor()
cursor.execute("SET NAMES utf8")
cursor.execute("select * from attribute")
cds = cursor.fetchall()
for row in cds:
for r in row:
print r
print 10*"----"
初试Python 操作Mysql
最新推荐文章于 2022-04-12 14:51:26 发布
本文提供了一个使用 Python 连接 MySQL 数据库并执行数据查询的具体实例。通过该示例,读者可以了解如何利用 Python 的 MySQLdb 库来设置数据库连接、执行 SQL 命令以及获取查询结果。
757

被折叠的 条评论
为什么被折叠?



