#!/usr/bin/python
#coding=utf-8

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("192.168.1.250","root","123456","mydb" )

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()

#查询username表内数据条数
reCount=cursor.execute('select * from username')
#抓取所有条数的信息
data_username=cursor.fetchall()

print "Database version : %s " % data
print data_username
# 关闭数据库连接
db.close()

posted on 2017-10-29 15:35  jamezhan  阅读(929)  评论(0编辑  收藏  举报