Python 官方文档:入门教程 => 点击学习
首页python学习应用文章阅读 字体:小 中 大上一篇:Python安装Mysql模块操作mysqlpython 输出sql语句日期:2014-06-26 17:43:12浏览:15次评论:0条作者:ylxhzjw评论#!/usr/
日期:2014-06-26 17:43:12浏览:15次评论:0条作者:ylxhzjw评论
#!/usr/bin/env python
#coding=utf-8
import MySQLdb
#建立和数据库系统的连接
conn = MySQLdb.connect(host='localhost', user='root',passwd='test')
#选择数据库
conn.select_db('python');
cursor.execute('set profiling = 1')
#获取操作游标
cursor = conn.cursor()
a=cursor.execute("""select * from test """)
print a
print cursor.fetchall()
try:
cursor.execute('SELECT * FROM aaa where name = %s',[admin])
except Exception:
cursor.execute('show profiles')
for row in cursor:
print(row)
cursor.execute('set profiling = 0')
conn.close()
文章来源:
Http://blog.zhanjingwen.cn/python-%e8%be%93%e5%87%basql%e8%af%ad%e5%8f%a5/
下一篇:需要读的几本专业书
--结束END--
本文标题: python 输出sql语句
本文链接: https://www.lsjlt.com/news/189792.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0