1.连接MySQL进入命令行模式
vim mysql_douguo_data.sh
#!/bin/sh
/usr/local/mysql/bin/mysql -u hadooper -h192.168.1.131 douguo_data -p"hadoopaaa";
2.连接MySQL执行sql获取数据
# query languages
QUERYA="select concat_ws(',',concat_ws('',id,subject),right(send_time,5)) from dd_sys_mail_set where send_type='day';"
# query from mysql
count_a=`/usr/local/mysql/bin/mysql -h${HOSTNAME} -u${USERNAME} -p${PASSWORD} -D ${DBNAME} -e "${QUERYA}" --skip-column-name`
# echo in data files and delete the first line 'log in file /var/mysql/query.log'
echo "${count_a}" | sed 's/\t/,/g' > ${_WORK_DIR}/tmp/queryloga.log