//pip install redis

import redis
r=redis.Redis(host='112.124.26.204',port=6379,db=0)
s=r.keys('CircleInfo:*')
print(s)

 

 

//pip install MySql-python
//如果报错,需要下载

import MySQLdb
conn=MySQLdb.connect(host='192.168.0.1',user="root",passwd="abc",db="def")
cursor=conn.cursor()
cursor.execute("select * from circles")

 

#demo



#pip install redis

import redis
import MySQLdb

#query from redis
r=redis.Redis(host='112.124.26.204',port=6379,db=0)
s=r.keys('CircleInfo:*')

#build mysql connection
conn=MySQLdb.connect(host='112.124.26.204',user='root',passwd='lyy^zy-db[2013]',db='lyy_wecircle')
cursor=conn.cursor()
for key in s:
    print("circle_id:"+key[11:])
    sql ='select name from circles where `status`= 1 and id= %s';
    cursor.execute(sql,[key[11:]]);
    rows = cursor.fetchone()
    if rows==None:
        #delete from redis
        print("circle_id:"+key[11:]+" delete from redis")
        # r.delete(key)

 

#!/usr/bin/python
# -*- coding: utf-8 -*-
#python 连接mysql 和 mssql
import mysqldbhelper
#mysqldbhelper 需要安装模块
import pymssql
#pymssql 需要安装模块
import sys

#设置中文编码
reload(sys)
sys.setdefaultencoding('utf-8')


print("===========mysql============")
mysql = mysqldbhelper.DatabaseConnection('192.168.1.127',user='root',passwd='123456',db='mysql')

balance = mysql.get_one("SELECT * FROM db_bankroll.T_UserAccountDetail WHERE user_id = %s " ,  (-1,))

print(balance[4])
print(float(balance[4]))

print("===========mssql============")
mssql=pymssql.connect(host="192.168.1.168",user="sa",password="123",database="TanBao")
cur=mssql.cursor()
cur.execute('SELECT username FROM [User] WHERE UserID=1' )
row = cur.fetchone()
while row:
    print(row[0])
    row = cur.fetchone()
mssql.close()