码迷,mamicode.com
首页 > 数据库 > 详细

python操作数据库

时间:2017-08-08 16:48:47      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:py

#!/usr/bin/env python
#encoding:utf-8
import MySQLdb
print "<html>"
print "<body>"
print "<h1>book</h1>"
print "<ul>"
connection = MySQLdb.connect(user="root", passwd="123456", db="zabbix")
cursor = connection.cursor()
cursor.execute("SELECT * FROM users")
for row in cursor.fetchall():
    print "<li>%s</li>" % row[0]
print "</ul>"
print "</body></html>"


[root@bogon ~]# python mysql.py
<html>
<body>
<h1>book</h1>
<ul>
<li>1</li>
<li>2</li>
</ul>
</body></html>
[root@bogon ~]#

yum install MySQL-python

本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1954439

python操作数据库

标签:py

原文地址:http://wsxxsl.blog.51cto.com/9085838/1954439

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!