shell读取mysql数据库两种方式

来源:互联网 发布:战地1狙击枪数据 编辑:程序博客网 时间:2024/05/19 03:47
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
   
原创粉丝点击