Mysql: Can't have all SQL requests logged with docker-compose?

Created on 18 Apr 2017  路  2Comments  路  Source: docker-library/mysql

Hello there!

Theme

I am trying to log all MySQL requests, using general query logs, in a file or in Docker logs collector.
https://dev.mysql.com/doc/refman/5.7/en/query-log.html

Configuration

I run my Docker custom image with Docker compose.

Dockerfile

FROM mysql:5.7

# Setup the custom configuration
ADD mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf

# Forward logs to docker log collector
RUN ln -sf /dev/stdout /var/log/mysql/mysql.log

# Setup MySQL init files
ADD sql/default-database.sql /docker-entrypoint-initdb.d/default-database.sql
ADD sql/default-user.sql /docker-entrypoint-initdb.d/default-user.sql

# Start mysql
RUN service mysql restart

mysqlnd.cnf

[mysqld]
pid-file                = /var/run/mysqld/mysqld.pid
socket                  = /var/run/mysqld/mysqld.sock
datadir                 = /var/lib/mysql
# Log files
general_log                 = 1
general_log_file            = /var/log/mysql/mysql.log

docker-compose.yml

version: '2'

services:
  web:
    build: ../app-web/
    ports:
     - "80:80"
    tty: true
    # Add a volume to link php code on the host and inside the container
    volumes:
     - /var/www/my_app:/usr/share/nginx/html/my_app
     - /var/www/my_app/docker_files/docker-assistant:/usr/share/nginx/html/assistant
    # Add hostnames to allow devs to call special url to open sites
    extra_hosts:
     - "localhost:127.0.0.1"
     - "assistant.docker:127.0.0.1"
     - "my_app.my_company.dev:127.0.0.1"
    depends_on:
     - custom-php
     - custom-mysql
     - custom-mongo
     - custom-node
    links:
     - custom-php:custom-php
     - custom-mysql:custom-mysql
     - custom-mongo:custom-mongo

  custom-php:
    build: ../app-php/
    ports:
     - "50:50"
    volumes:
     - /var/www/my_app:/usr/share/nginx/html/my_app
     - /var/www/my_app/docker_files/docker-assistant:/usr/share/nginx/html/assistant

  custom-mysql:
    build: ../app-mysql/
    #tty: true
    volumes:
     - /var/lib/mysql:/var/lib/mysql
     - /var/www/my_app/sql:/usr/share/sql
    environment:
     - MYSQL_ROOT_PASSWORD=rootpwd
     - MYSQL_DATABASE=appdb
     - MYSQL_USER=app
     - MYSQL_PASSWORD=apppwd

  custom-mongo:
    build: ../app-mongo/
    volumes:
     - /var/lib/mongodb:/data/db

  custom-node:
    build: ../app-npm/
    tty: true

Questions

  • Is that possible to log all queries with dockerized MySQL?
  • If yes, what am I doing wrong?

Most helpful comment

The OP example here is overly complex. That being said, I tried all sorts of combinations of --general_log=1 with --general_log_file set to /dev/stdout, /dev/stderr, /proc/1/fd/1, etc (with and without --log-output=FILE), and they all end up with a similar error:

2017-12-27T00:25:48.416049Z 0 [ERROR] Could not use /dev/stdout for logging (error 2 - No such file or directory). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL GENERAL_LOG=ON" or restart the MySQL server.

So, I don't know whether it's possible for the general query log to be included in stdout as is desired here -- sending them to a file should work fine, though.

All that aside, this isn't really an issue with the image (and certainly not one we could fix) and more a request for help configuring upstream, so I'm going to close.

All 2 comments

I use mysql-proxy for collect query:
docker-compose.yml

The OP example here is overly complex. That being said, I tried all sorts of combinations of --general_log=1 with --general_log_file set to /dev/stdout, /dev/stderr, /proc/1/fd/1, etc (with and without --log-output=FILE), and they all end up with a similar error:

2017-12-27T00:25:48.416049Z 0 [ERROR] Could not use /dev/stdout for logging (error 2 - No such file or directory). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL GENERAL_LOG=ON" or restart the MySQL server.

So, I don't know whether it's possible for the general query log to be included in stdout as is desired here -- sending them to a file should work fine, though.

All that aside, this isn't really an issue with the image (and certainly not one we could fix) and more a request for help configuring upstream, so I'm going to close.

Was this page helpful?
0 / 5 - 0 ratings