Small exercise - store data in MySQL database into redis

#pymysql, json, redis 
#1, connect to the database, find all the data in the database, the cursor type should use pymysql.curosrs.DictCour
#2, find all the data [ {"id":1,"passwd":"49487dd4f94008a6110275e48ad09448 ","username":"niuhayang","is_admin":1}]
#3. Loop the list, get the usernamer, use the username as the key
#4, then convert this small dictionary into json, and save it in it is ok.
import pymysql,json,redis
r = redis.Redis(host='118.24.3.40',password='HK139bc&*',db=1,port=6379)
conn = pymysql.connect(host='118.24.3.40',user ='jxz',passwd='123456',db='jxz',charset='utf8')
cur = conn.cursor(cursor=pymysql.cursors.DictCursor)#dictionary display
cur.execute('select * from my_user ;')
all_data = cur.fetchall()
for data in all_data:
k = data.get('


conn.close()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325571814&siteId=291194637