shell脚本查询mysql
来源:互联网 发布:mac右键菜单设置 编辑:程序博客网 时间:2024/05/18 03:44
接到统计需求,需要对一批对一批uid过滤,只保留10月1日之后注册的uid,用户注册时间可以从mysql里面拿,写了个shell脚本
ps:用户信息使用十库十表存储,像 12345这个uid存储在5这个库中的4这个表里面
#! /bin/bashhostip="107.0.0.1"port=6304username="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" fidone
有个缺点,查询的时候有点慢,可能每次查询都需要连接一次数据库的原因,哪位大牛指点一下有没有好点的方式~
阅读全文
0 0
- shell脚本查询mysql
- Shell脚本实现远程MySQL自动查询
- shell脚本分析mysql慢查询日志(slow log)
- shell脚本查询MYSQL数据库并进行相应处理
- shell脚本查询数据库
- mysql备份shell脚本
- Shell脚本链接Mysql
- shell脚本操作mysql
- [shell]mysql backup脚本
- 【shell脚本】mysql每日备份shell脚本
- [mysql] shell 脚本运行mysql
- shell 封装mysql查询
- shell自动连接mysql后进行查询和自动备份脚本
- mysql备份shell脚本(2)
- mysql备份恢复shell脚本
- mysql数据库备份shell脚本
- SHELL下执行MYSQL脚本
- shell脚本备份mysql数据库
- Linux部署Apache ActiveMQ 5.14.1
- 算法-快速排序
- 如何实现高可用的redis集群
- maven 打包时关于编码的WARNING
- JAVA的替代者Kotlin
- shell脚本查询mysql
- Android 音视频去回声、降噪
- MySQL数据库-表之间的关系(精华)
- 学习prototype.
- 引用和指针
- 接口测试之发包工具介绍
- Linux 开机时网络自动连接
- Centos7+django1.11+apache2.4+mod_wsgi4.5+python3.6项目部署
- Android逆向之旅---动态方式破解apk前奏篇(Eclipse动态调试smail源码)