清理events表
#!/bin/bash
#this script name is delete_events.sh
host="localhost"
socket="/data/perconadata5.6/mysql.sock"
user="zabbix"
pass="zabbix"
port="3306"
time=`date -d "last-month" +%Y-%m-01`
mysql -u $user -p$pass -h$host  -S $socket -P $port <<EOF
use zabbix;
delete  from  events where  clock <= UNIX_TIMESTAMP('${time}') limit 40000;
EOF


------------------------------------------------------------------------------

先暂停zabbix.当然是service zabbix_server stop

然后最好也把http停掉 service httpd stop

连上数据库:

mysql -u root(zabbix) -p
use zabbix

核心语句:    排序表的大小
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'zabbix'
ORDER BY (data_length + index_length) DESC;
truncate table history;
truncate table history_uint;
truncate table alerts;
truncate table trends_uint;
truncate table trends;
truncate table history_text;
truncate table events;

使用delete的话,也会清空数据,但是不会更改表中的记录ID.

results matching ""

    No results matching ""