shell脚本链接数据库导出数据

xiaoxiao2021-02-28  9

#!/bin/bash #变量定义 #服务器域名 hostname="abc"; #端口号 prot="5154"; #用户名 user="bidding"; #密码 password="C01"; #数据库名 dbname="bidding_promotion"; FilePath1="/opt/lsn/SecondCateIds.log"; #若文件存在,则删除文件 if [ -f ${FilePath1} ]; then rm ${FilePath1} fi #创建文件 touch ${FilePath1}; TIME1=$(date "+%Y-%m-%d %H:%M:%S") echo -e "\n\n========================"${TIME1}" start handle!\n" echo -e '-h'${hostname} '-P'${prot} '-u'${user} '-p'${password} '-D'${dbname} '-e"'${sqlstr}'"', #从数据库promotion中读取cateWhiteList表信息--skip-column-names:去掉表头信息 sqlstr="select cate_id from cate_white_list where cate_type=2 and ad_source=1 and is_open=1 and category_id in(9224,13941)"; mysql -h${hostname} -P${prot} -u${user} -p${password} -D${dbname} --skip-column-names -e"${sqlstr}" > ${FilePath1} if [ $? -ne 0 ]; then echo "读取表失败" exit 1 fi
转载请注明原文地址: https://www.6miu.com/read-800086.html

最新回复(0)