shell脚本查询mysql
发布时间:2020-12-15 09:22:57 所属栏目:安全 来源:网络整理
导读:接到统计需求,需要对一批对一批uid过滤,只保留10月1日之后注册的uid,用户注册时间可以从mysql里面拿,写了个shell脚本 ps:用户信息使用十库十表存储,像 12345这个uid存储在5这个库中的4这个表里面 #! /bin/bash hostip= "107.0.0.1" port= 6304 usernam
接到统计需求,需要对一批对一批uid过滤,只保留10月1日之后注册的uid,用户注册时间可以从mysql里面拿,写了个shell脚本 #! /bin/bash
hostip="107.0.0.1"
port=6304
username="net_budao_root"
pwd="123456"
database="db_bd"
first_login_time="2017-10-01"
#构造用户信息表,用户信息使用十库十表
function getDbTb(){
first=${1:0-1:1}
second=${1:0-2:1}
echo "db_budao_"$first".t_user_"$second
}
#查询这个uid是否存在
function exist(){
tb=`getDbTb $1`
sql="select count(1) from $tb where uid = $1 and from_unixtime(first_login_time) > "$first_login_time""
res=(`mysql -h10.25.68.144 -P6304 -unet_budao_root -ppbVo9teu -Ddb_bd -e "$sql" | awk 'NR>1'`) # NR>1 去掉查询的第一行
echo $res
}
for uid in $(cat $1)
do
res=`exist $uid`
if [ $res -eq 1 ]
then
echo $uid >> $1".dump"
# else
# echo "false"
fi
done
有个缺点,查询的时候有点慢,可能每次查询都需要连接一次数据库的原因,哪位大牛指点一下有没有好点的方式~ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |