如果使用Sqoop删除mysql中的数据,并且传递动态日期参数,则使用下方的方法:
创建一个sh文件,内容如下:
#!/bin/sh
## 环境变量生效
. /etc/profile
#【调度删除导入所在月数据量】
deletym=$(date -d last-day +%Y%m)
sqoop eval --connect jdbc:mysql://112.112.10.127:3060/yangyang8848--username root --password yangyang8848--query "delete from yangyang8848 Where ym = '$deletym'"
sqoop eval --connect jdbc:mysql://112.112.10.127:3060/yangyang8848--username root --password yangyang8848--query "delete from yangyang8848 Where ym = '$deletym'"
sqoop export --connect "jdbc:mysql://112.112.10.127:3060/yangyang8848?useUnicode=true&characterEncoding=utf-8" --username root --password yangyang8848 --table yangyang8848 -hcatalog-database yangyang8848 --hcatalog-table yangyang8848
sqoop export --connect "jdbc:mysql://112.112.10.127:3060/yangyang8848?useUnicode=true&characterEncoding=utf-8" --username root --password yangyang8848 --table yangyang8848 -hcatalog-database yangyang8848 --hcatalog-table yangyang8848
然后通过命令执行sh文件,可能需要sh文件提权,然后才能执行!