clean_mysql.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #! /bin/bash
  2. . /usr/local/service/sagaApps/bi_saga/dwh_saga/task_day/config.sh
  3. if [ -n "$2" ] ;then
  4. do_date=$2
  5. else
  6. echo "====没有输入数据的日期,取当前时间的前一天===="
  7. do_date=$(date -d yesterday +"%Y-%m-%d")
  8. fi
  9. echo "$do_date"
  10. host=$MYSQL_HOST
  11. username=$MYSQL_USER
  12. password=$MYSQL_PASSWORD
  13. database=dwh_saga
  14. del_energy_15_min="truncate table energy_15_min;"
  15. del_co2_15_min="truncate table co2_15_min;"
  16. del_pm25_15_min="truncate table pm25_15_min;"
  17. del_hcho_15_min="truncate table hcho_15_min;"
  18. del_temperature_15_min="truncate table temperature_15_min;"
  19. del_humidity_15_min="truncate table humidity_15_min;"
  20. ## 历史数据一次性导入后,需要删除 mysql 中的冗余数据
  21. clean_energy_15(){
  22. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_energy_15_min}"
  23. }
  24. clean_co2_15_min(){
  25. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_co2_15_min}"
  26. }
  27. clean_pm25_15_min(){
  28. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_pm25_15_min}"
  29. }
  30. clean_hcho_15_min(){
  31. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_hcho_15_min}"
  32. }
  33. clean_temperature_15_min(){
  34. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_temperature_15_min}"
  35. }
  36. clean_humidity_15_min(){
  37. mysql -h"${host}" -P3306 -u"${username}" -p"${password}" ${database} -e "${del_humidity_15_min}"
  38. }
  39. case $1 in
  40. "all")
  41. clean_energy_15
  42. clean_co2_15_min
  43. clean_pm25_15_min
  44. clean_hcho_15_min
  45. clean_temperature_15_min
  46. clean_humidity_15_min
  47. ;;
  48. "clean_energy_15")
  49. clean_energy_15
  50. ;;
  51. "clean_co2_15_min")
  52. clean_co2_15_min
  53. ;;
  54. "clean_pm25_15_min")
  55. clean_pm25_15_min
  56. ;;
  57. "clean_hcho_15_min")
  58. clean_hcho_15_min
  59. ;;
  60. "clean_temperature_15_min")
  61. clean_temperature_15_min
  62. ;;
  63. "clean_humidity_15_min")
  64. clean_humidity_15_min
  65. ;;
  66. esac