清理脚本
#!/bin/bash Date=`date -d $(date -d "-30 day" +%Y%m%d) +%s` /usr/local/mysql/bin/mysql --login-path=zabbix -e" use zabbix; DELETE FROM history WHERE 'clock' < $Date; optimize table history; DELETE FROM history_str WHERE 'clock' < $Date; optimize table history_str; DELETE FROM history_uint WHERE 'clock' < $Date; optimize table history_uint; DELETE FROM trends WHERE 'clock' < $Date; optimize table trends; DELETE FROM trends_uint WHERE 'clock' < $Date; optimize table trends_uint; DELETE FROM events WHERE 'clock' < $Date; optimize table events; " #此脚本删除30天之前的数据,时间可可根据需求自行修改
注意:如果MySQL数据库是5.6.6需要先设置免密码登陆
参考博文
https://my.oschina.net/ifraincoat/blog/485834
https://shazi.info/mysql-%E5%9F%B7%E8%A1%8C-bash-script-%E5%87%BA%E7%8F%BE-warning-using-a-password-on-the-command-line-interface-can-be-insecure/
转载于:https://blog.51cto.com/linux10000/1943827