shell读取mysql数据库两种方式

mysql -hxxx -P3306 -uxxxx -pxxx test_bi -s -e \
"select m_ip,m_user,m_passwd,m_db,m_port,m_table,h_db,h_table,conditions from t_sqoop_task_info where is_valid=1 and task_id=67 limit 1" \
| while read m_ip m_user m_passwd m_db m_port m_table h_db h_table conditions

do
    m_conditions=${conditions//'$'dt/`echo $time`}
    echo ${m_ip}...${m_user}...${m_passwd}...${m_db}...${m_port}...${m_table}...${h_db}...${h_table}
    read ct <<< $(echo `mysql -h$m_ip -P$m_port -u$m_user -p$m_passwd -D$m_db -s -e "select count(*) ct from $m_table where $m_conditions"`)
    echo mysql -h$m_ip -P$m_port -u$m_user -p$m_passwd -D$m_db -s -e "select count(*) ct from $m_table where $m_conditions"
    echo -e "${h_db}\t${h_table}\t${ct}" >> $data_path
done
   

猜你喜欢

转载自blog.csdn.net/oracle8090/article/details/76855040
今日推荐