shell 读取msyql

#!/bin/bash
HOST_IP='hyman'
USER='root'
PASSWD='123456'
DBNAME='zhenai_etl'

sql="SELECT t.data_id,t.databaseType,t.keep_day,s.host_ip,s.host_port,s.user_name,s.user_pwd
FROM t_src_interface_config t,t_server s 
WHERE t.server_tag = s.server_tag AND t.syn_to_db = 1;"

echo $sql

mysql -h$HOST_IP -u$USER -p$PASSWD $DBNAME -N -s -e "$sql"|while read topic dbtype keep_day host_ip host_port user_name user_pwd;
do 
echo "topic:$topic"
echo "dbtype:$dbtype"
echo "keepday:${keep_day}"
echo "hostip:$host_ip"
echo "hostport:$host_port"
echo "user_name:$user_name"
echo "user_pwd:$user_pwd"
done

a=10
b=20
if [ $a -eq $b ];then
	echo 'a is equal to b'
else
	echo 'not equal'
fi

猜你喜欢

转载自hymanliu.iteye.com/blog/2330359