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

#!/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
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值