主要应用到shell for循环
定义数据库连接信息
HOST_NAME=\'127.0.0.1\'
DB_PORT=\'3306\'
DB_NAME=\'数据库名\'
USER_NAME=\'root\'
PASSWD=\'root\'
TIME 当前时间戳 $() 注意date中间是有空格的
TIME=$(date \'+%s\')
-s 去掉表头
MYSQL_ETL="mysql -h${HOST_NAME} -P${DB_PORT} -u${USER_NAME} -p${PASSWD} ${DB_NAME} -s -e"
hive_table_sql="select user_id from mx_user where token_time >0 and online=1 and token_time <= ${TIME}"
hive_table=$($MYSQL_ETL "${hive_table_sql}")
for 变量 in 查出的数据 ,然后遍历这个变量 做 处理
for userid in $hive_table
do
此处逻辑处理(我这里的例子是查出再修改)
update_sql="update mx_user set online=0 where user_id=${userid}"
$($MYSQL_ETL "${update_sql}")
done