1

I am working on an existing Dockerfile that I have been asked to modify as less as possible. The docker image is based on a CentOS Linux image and is supposed to contain a MySQL service.

I want to enable the verbose logging for all the queries (i.e. general_log and general_log_file variables on the /etc/my.cnf file).

The MySQL service needs to be run in the mysqld_safe mode and I've checked that the configuration lines I am adding (see below the printf) are after the [mysqld_safe] line in the /etc/my.cnf file, so I am assuming this setting should be fine.

What I've done so far is adding to the Dockerfile the following statements:

RUN groupadd -r mysql && useradd -r -g mysql mysql

# [...] Lots of Mysql stuff regarding importing DBs etc.

# Adding some more configuration details to the database service
RUN printf '\n%s\n%s\n%s\n\n' '# Set General Log to log all the queries' 'general_log=1' 'general_log_file=/var/log/mysql_general.log' >> /etc/my.cnf

# Getting the new log file prepared to get written by the MySQL service
RUN touch /var/log/mysql_general.log
RUN chown mysql.mysql /var/log/mysql_general.log

# MySQL Port
EXPOSE 3306

ENTRYPOINT ["mysqld_safe"]

After building the docker image and running the docker container I see this in the /var/log folder:

-rw-r-----. 1 mysql mysql   5108 Nov 20 17:07 mysqld.log
-rw-r--r--. 1 mysql mysql   3880 Nov 20 17:44 mysql_general.log

If I grep the mysqld.log for keywords like ERROR or general I can not find anything interesting. The mysql_general.log file is empty.

I see this also this:

mysql> show variables like '%general_log%';
+------------------+----------------------------+
| Variable_name    | Value                      |
+------------------+----------------------------+
| general_log      | OFF                        |
| general_log_file | /var/run/mysqld/mysqld.log |
+------------------+----------------------------+
2 rows in set (0.00 sec)

mysql>

I am not able to get the SQL queries written in the log file, why?

TPPZ
  • 4,447
  • 10
  • 61
  • 106
  • Can you show us the output of your mysql error log? Btw: `RUN chown mysql.mysql /va...` has to be `RUN chown mysql:mysql /va...`. You have to seperate user and group by ":". – gregor Nov 20 '14 at 17:35
  • I've updated the details. The command `chown` with the dot `.` works fine for me, I don't know why. Thanks – TPPZ Nov 20 '14 at 17:49
  • this may help `https://stackoverflow.com/questions/5441972/how-to-see-log-files-in-mysql` – Windsooon Apr 27 '17 at 07:02

0 Answers0