clean_mysql.sh 1.9 KB

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