日志方便导入包装 mysql ( python )
时间:2010-09-27 来源:liukaiyi
参考 : mysql doc
# 创建存储空间 $> python mysql_by_log.py " create table test ( id int(11) unsigned NOT NULL AUTO_INCREMENT, at datetime DEFAULT NULL , ab varchar(20) DEFAULT NULL , auid varchar(20) DEFAULT NULL , pv int DEFAULT NULL , PRIMARY KEY (id), UNIQUE aaa (at,ab,auid) ); "
# 插入数据 # mysql DUPLICATE KEY $> python ./mysql_by_log.py ' insert into test values ( NULL,DATE_FORMAT( "#at#" , "%Y-%m-%d" ),"#ab#","#auid#",1) on duplicate key update pv = pv + 1 ; ' 'cat /data/tongji/iphone_app/imusic/app*/2010/09/20/*' > insert_num = 65809 , insert_err_num = 2666
real 0m14.397s user 0m1.928s sys 0m0.980s
# 查询展现 用户去重复 $> time ./mysql_by_log.py ' select count( distinct auid ) from test ' > 2683 $> time cat /data/tongji/iphone_app/imusic/app*/2010/09/20/* |perl -nle ' print $1 if /auid=(.*?)</ ' |sort -u |wc -l > 2684
import sys,os,re |