时间:2021-07-01 10:21:17 帮助过:54人阅读
if __name__=="__main__":
client=client_conn()
conn = MySQLdb.connect(host="172.161.110.10", user="dlan", passwd="root123", port=5029, db=‘coolqi‘, charset=‘utf8‘)
cur = conn.cursor()
sql="select * from ca_record where ca_time>=STR_TO_DATE(‘20170720‘,‘%Y%m%d‘)"
print sql
cur.execute(sql)
data=cur.fetchall()
for k in xrange(len(data)):
datalist2=[]
rowKey=data[k][0]
print rowKey
user_id=data[k][1]
ca_result=data[k][2]
ca_time=data[k][3]
real_name=data[k][4]
id_card=data[k][5]
sex=data[k][6]
datalist=[user_id,ca_result,ca_time,real_name,id_card,sex]
datalist1=["user_id","ca_result","ca_time","real_name","id_card","sex"]
for j in range(len(datalist)):
args=str(datalist[j])
#print args
if isinstance(args,str):
mutations="[Mutation(column="+"‘"+datalist1[j]+‘:‘+str(j)+"‘"+","+"value="+"‘"+str(args)+"‘)"+"]"
datalist2.append(mutations)
#print datalist2
client.mutateRow(‘ca_record‘,str(rowKey),[Mutation(column=datalist1[j]+‘:‘+str(j),value=str(args))])
#client.mutateRows(‘ca_record‘,datalist2)
###在for k in xrange(len(data)): 可以利用enumerate()函数减少上面的循环 .
本文出自 “DBAspace” 博客,请务必保留此出处http://dbaspace.blog.51cto.com/6873717/1950007
MySQL to Hbase 数据的抽取
标签:mysql to hbase