How make a wait import sql file?

11/7/2019

I have 3 containers: nginx, php-fpm and mysql 5.7 . I import a large SQL file with volume. When I connect to the container mysql, see only part of the tables.

How to properly wait for SQL file import. Could give an example of use (healthcheck or .sh file)?

-- user246328
docker
docker-compose
kubernetes-health-check
mysql

1 Answer

11/7/2019

Well there is this pipe viewer which you can use to import from dump files. It nicely explained inside this DBA case.

You can use livenessProbe to check if mysql is responding, this might look like the following:

livenessProbe:
  exec:
    command: ["mysqladmin", "ping"]
  initialDelaySeconds: 30
  periodSeconds: 10
  timeoutSeconds: 5

It waits 30 second before first check, after that each 10 seconds there is another check. Timeout for failure is set to 5 seconds.

You can also use readinessProbe which is used to check if database is ready for accepting connections:

readinessProbe:
  exec:
     # Check we can execute queries over TCP (skip-networking is off).
    command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
  initialDelaySeconds: 5
  periodSeconds: 2
  timeoutSeconds: 1

Command will be executed after 5 seconds from container start and it will be executed each 2 seconds. Probe will fail after 1 second of timeout. The pod won't be in Ready state so it won't accept connections if the probe is failing.

-- Crou
Source: StackOverflow