Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable slow query / general log to output to stdout #894

Open
tsposato opened this issue Jul 18, 2022 · 7 comments
Open

Enable slow query / general log to output to stdout #894

tsposato opened this issue Jul 18, 2022 · 7 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@tsposato
Copy link

Currently, the system logs output in a way where you can use 'docker logs' to view them.
This is beneficial for a variety of reasons as you don't need to specifically access the containers filesystem to view them.
Is there a way to also enable the slow query or general query log to output in the same way?

@tianon
Copy link
Member

tianon commented Jul 18, 2022

I haven't tried, but I bet you could do something with /dev/stdout + https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_slow_query_log_file 👀

(ie, --slow-query-log-file=/dev/stdout or --slow-query-log-file=/dev/stderr)

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Jul 25, 2022
@tsposato
Copy link
Author

I haven't tried, but I bet you could do something with /dev/stdout + https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_slow_query_log_file 👀

(ie, --slow-query-log-file=/dev/stdout or --slow-query-log-file=/dev/stderr)

I'll try this and see how I go. Will report back my findings.

@dotneet
Copy link

dotneet commented Aug 10, 2022

--slow-query-log-file=/dev/stdout doesn't work on my environment.

2022-08-10T06:39:23.313012Z 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 SLOW_QUERY_LOG=ON" or restart the MySQL server.

@tianon
Copy link
Member

tianon commented Aug 11, 2022

That's weird - it works OK here: 😬

$ docker run -it --rm --pull=always -e MYSQL_RANDOM_ROOT_PASSWORD=1 mysql:8 --slow-query-log-file=/dev/stdout
8: Pulling from library/mysql
32c1bf40aba1: Pull complete 
3ac22f3a638d: Pull complete 
b1e7273ed05e: Pull complete 
20be45a0c6ab: Pull complete 
410a229693ff: Pull complete 
1ce71e3a9b88: Pull complete 
c93c823af05b: Pull complete 
c6752c4d09c7: Pull complete 
d7f2cfe3efcb: Pull complete 
916f32cb0394: Pull complete 
0d62a5f9a14f: Pull complete 
Digest: sha256:ce2ae3bd3e9f001435c4671cf073d1d5ae55d138b16927268474fc54ba09ed79
Status: Downloaded newer image for mysql:8
2022-08-11 00:05:27+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2022-08-11 00:05:27+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-08-11 00:05:27+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2022-08-11 00:05:27+00:00 [Note] [Entrypoint]: Initializing database files
2022-08-11T00:05:27.410861Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-08-11T00:05:27.410932Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.30) initializing of server in progress as process 42
2022-08-11T00:05:27.416907Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-11T00:05:27.951388Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-11T00:05:29.450069Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-08-11 00:05:32+00:00 [Note] [Entrypoint]: Database files initialized
2022-08-11 00:05:32+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/c82b49dded53.err
mysqld is running as pid 95
2022-08-11 00:05:33+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2022-08-11 00:05:34+00:00 [Note] [Entrypoint]: GENERATED ROOT PASSWORD: 7yU3dQrzXNgwZjWEvBkew2HsC72fd9nA

2022-08-11 00:05:34+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-08-11 00:05:36+00:00 [Note] [Entrypoint]: Temporary server stopped

2022-08-11 00:05:36+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2022-08-11T00:05:36.661573Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-08-11T00:05:36.662487Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 1
2022-08-11T00:05:36.667203Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-11T00:05:36.757377Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-11T00:05:36.937099Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-08-11T00:05:36.937125Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-08-11T00:05:36.938629Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-08-11T00:05:36.953614Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-08-11T00:05:36.953628Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

@tianon
Copy link
Member

tianon commented Oct 6, 2022

For further help, I'd suggest a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

@tianon tianon closed this as completed Oct 6, 2022
@fnwbr
Copy link

fnwbr commented Mar 3, 2025

@tianon You forgot to pass --general=log=1; please re-open this issue.
Verified this issue both on 8.0 but also latest 8.4.4:

docker run -it --rm --pull=always -e MYSQL_RANDOM_ROOT_PASSWORD=1 mysql:8 --general-log=1 --general-log-file=/dev/stdout
2025-03-03T17:41:36.688030Z 0 [ERROR] [MY-011263] [Server] 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.

EDIT: To clarify, this issue exists for both, general_log but also slow_query_log.

@tianon tianon reopened this Mar 3, 2025
@yosifkit
Copy link
Member

yosifkit commented Mar 3, 2025

Look like stdout or stderr are not supported (https://stackoverflow.com/a/32939348); only files, tables, or none are supported (https://dev.mysql.com/doc/refman/8.4/en/log-destinations.html). So, there is nothing we can document or add to the image to change this. If you want this functionality, submit a feature request with upstream MySQL (https://bugs.mysql.com/, https://github.com/mysql/mysql-server).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

6 participants