Ad Widget

Collapse

[5.0.3][Docker] Deleting old data from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randomizedname
    Junior Member
    • Sep 2020
    • 10

    #1

    [5.0.3][Docker] Deleting old data from mysql

    Hi,
    I'm running dockerized Zabbix Server 5.0.3. Mysql database is growing fast and I need the delete old data. The problem is I don't know how to do it. Zabbix is started using docker-compose_v3_alpine_mysql_latest.yaml file.

    I've tried the following:

    1. Login to mysql container (zabbix/zabbix-server-mysql:alpine-5.0-latest):
    Code:
    docker exec -it 5f35299502af  /bin/bash
    2. Then inside container:
    Code:
    mysql -u root -p
    , with default password
    3. System responds with:
    Code:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
    This is true, /run/mysqld/mysqld.sock not exist and it seems there is no mysqld.sock anywhere in the system.
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    Presumably your Zabbix server and your zabbix web interface can connect to the database, correct?

    So, your zabbix_server.conf has the parameters you would need for DBHost, DBName, DBUser, DBPassword, and possibly DBPort. Why not just run mysql from the Zabbix server and pass the mysql command those parameters (you can use just '-p ' and no password on the command line, to be prompted for the database password)? I mean, if the zabbix_serverd process can connect, then you should be able to connect from the same origin host using the exact same parameters.

    Comment

    • randomizedname
      Junior Member
      • Sep 2020
      • 10

      #3
      Originally posted by tim.mooney
      Presumably your Zabbix server and your zabbix web interface can connect to the database, correct?
      Yes it can, but this is done inside docker's internal networks. I don't have access to it form host. At least netstat doesnt show any mysql port available.

      Anyway, I was able to find source of the problem. I was connecting to the wrong container... Now it works. I leave the script here, maybe it helps someone sometime.

      Code:
      #!/bin/bash
      CONTAINER='zabbix-docker-50_mysql-server_1'
      docker exec $CONTAINER mysql -u zabbix --password='zabbix' -D zabbix --execute="
      SET @history_interval = 7;
      SET @trends_interval = 7;
      DELETE FROM alerts WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM acknowledges WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM events WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM history WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM history_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM history_str WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM history_text WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM history_log WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
      DELETE FROM trends WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
      DELETE FROM trends_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
      exit"
      exit 0

      Comment

      Working...