V
V
Vadim Stepanenko2021-11-04 21:29:51
MySQL
Vadim Stepanenko, 2021-11-04 21:29:51

How to write slow queries in the project folder in mysql docker container?

Hey! there is a docker with a lamp container. The database config is like this:

db:
    image: library/mysql:8.0.20
    ports:
      - "3307:3306"
    environment:
      - MYSQL_DATABASE=
      - MYSQL_ROOT_PASSWORD=
    volumes:
      - "./resources/docker/config/my.cfg:/etc/mysql/conf.d/config-file.cnf"
      - "./resources/docker/logs/slow.cfg:/var/log/mysql/mysql-slow.log"
      - "./resources/schema/schema.sql:/docker-entrypoint-initdb.d/1-schema.sql"


my.cfg
[mysqld]
bind-address = 0.0.0.0

innodb_buffer_pool_size = 1024M

default_authentication_plugin=mysql_native_password

# Slow Queries
slow_query_log = 1
long_query_time = 5
slow_query_log_file = /var/log/mysql/mysql-slow.log
log-queries-not-using-indexes = 1

# Unicode
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci


When docker-compose build, docker-compose up file in ./resources/docker/logs/slow.cfg is created, but nothing is written there. Docker exec [container id] /var/log/mysql/mysql-slow.log throws an error
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "/var/log/mysql/mysql-slow.log": permission denied: unknown


Tell me, what could be wrong? By the last mistake, I suppose there are no rights to read the /var/log/mysql/mysql-slow.log file, but where should they be specified?
And is it even possible to "broadcast" mysql-slow.log from the docker container "outside" to the project file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-11-04
@Vadim1899

Before starting docker, create an empty file and give full permissions (of course slow.log and not slow.cfg)

touch ./resources/docker/logs/slow.log
chown 777 ./resources/docker/logs/slow.log

- "./resources/docker/logs/slow.log:/var/log/mysql/mysql-slow.log"

Better yet, throw the entire logs folder into the container
volumes:
      - "./resources/docker/config/my.cfg:/etc/mysql/conf.d/config-file.cnf"
      - "./resources/docker/logs/mysql/:/var/log/mysql/"
      - "./resources/schema/schema.sql:/docker-entrypoint-initdb.d/1-schema.sql"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question