python 连接数据库
2013-06-17 00:00
330 查看
#!/usr/bin/python
import MySQLdb
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='cdyanfa',port=3306)
cur=conn.cursor()
conn.select_db('nova')
count=cur.execute('select * from instances')
print 'there has %s rows record' % count
cur.execute('SELECT uuid,hostname FROM instances where deleted = 0')
print "Rows selected:", cur.rowcount
for row in cur.fetchall():
print "note : ", row[0], row[1]
conn.commit()
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
import MySQLdb
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='cdyanfa',port=3306)
cur=conn.cursor()
conn.select_db('nova')
count=cur.execute('select * from instances')
print 'there has %s rows record' % count
cur.execute('SELECT uuid,hostname FROM instances where deleted = 0')
print "Rows selected:", cur.rowcount
for row in cur.fetchall():
print "note : ", row[0], row[1]
conn.commit()
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
相关文章推荐
- Python连接Mysql&&解决数据库汉字显示乱码问题
- Python 3.x 连接数据库(pymysql 方式)
- Python:安装setuptools,安装MySQLdb模块,连接数据库代码
- python Django连接数据库问题
- Python - 连接msql数据库
- MySQl-python模块,python连接数据库出现的问题
- Python 连接数据库
- python脚本――生成EXCEL,连接数据库,并将指定数据写入EXCEL
- Python MySQLdb连接数据库之phpmyadmin报错解决方法
- Python连接数据库
- python连接数据库
- Python连接数据库-pyodbc
- python实现简单数据库连接及操作
- Python连接数据库学习之DB-API详解
- Python3 MySQL 数据库连接
- python:数据库连接操作入门
- python 连接操作 各类数据库
- Linux 下使用 Python 连接 Windows 服务器上的数据库
- python3之flask框架连接redis数据库
- python访问PostgreSQL数据库之连接库Psycopg2