Bug #99748 mysql.log gets always created
Submitted: 31 May 2020 15:03 Modified: 28 Jun 2021 13:57
Reporter: Peter VARGA Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:8.0.20 OS:Linux
Assigned to: Paul DuBois CPU Architecture:Any

[31 May 2020 15:03] Peter VARGA
Description:
I have these settings in my.cnf

[mysqld]
...
disable_log_bin
general-log      = false
general_log_file = /var/log/mysql/mysqld.general.log

long_query_time     = 1
slow_query_log      = false
slow_query_log_file = /var/log/mysql/mysqld.slow.query.log

[safe_mysqld]
log-error = /var/log/mysql/mysqld.log

[mysqld_multi]
...
log        = /var/log/mysql/mysqld_multi.log

Restarting/starting the MySQL server creates the empty file /var/log/mysql.log and it never gets filled.

I suppose it's created by mistake as mysql.log is outdated in MySQL 8.0.20

How to repeat:
Restarting/starting MySQL server.

Suggested fix:
Can you please explain why mysql.log is created and, if it's done intentionally how can I disable the creation.
[3 Jun 2020 2:29] MySQL Verification Team
Hi,

If you add log-error=/var/log/mysql/mysqld.log

in [mysqld] section too and not only mysqld_safe do you still get it?

all best
Bogdan
[3 Jun 2020 7:32] Terje Røsten
Are you using RPM packages?

First, try to rename [safe_mysqld] section to [mysqld_safe].

However, the best fix is to remove any [mysqld_safe] or [safe_mysqld] section
and put 

 log-error = /var/log/mysql/mysqld.log

in [mysqld] section where it really belongs.
[3 Jun 2020 12:15] Peter VARGA
OK, adding the setting to the [mysqld] section fixed it.

But, why is the log file empty if I don't specify it explicitly in the [mysqld] section. This doesn't sound OK.

Now, the log file was filled with the messages from the MySQL restart.

Anyway, my system doesn't have mysqld_safe as stated here: https://dev.mysql.com/doc/refman/8.0/en/mysqld-safe.html

These are all mysql* executable files in my SUSE system:
mysql
mysql_config_editor
mysql_secure_installation
mysql_ssl_rsa_setup
mysql_tzinfo_to_sql
mysql_upgrade
mysqladmin
mysqlbinlog
mysqlcheck
mysqld_pre_systemd
mysqldump
mysqldumpslow
mysqlimport
mysqlpump
mysqlshow
mysqlslap
[3 Jun 2020 12:43] Terje Røsten
The systemd pre script only consider [mysqld] section in my.cnf:

 https://github.com/mysql/mysql-server/blob/8.0/scripts/systemd/mysqld_pre_systemd.in#L70

 log=$(get_option mysqld 'log[_-]error' "/var/log/mysql${instance:+-$instance}.log" $instance)

hence it don't find anything about log-error if [safe_mysqld] section is used
and fall back to default which is /var/log/mysql.log.

If /var/log/mysql.log is missing it will be re-created on every restart of mysql service,
which is exactly what you see.

These days where systemd is the standard, mysqld_safe is just legacy  and should not be used,
and any [mysqld_safe] or [safe_mysqld] section should be removed (or migrated to [mysqld]).
[3 Jun 2020 12:48] Terje Røsten
Reading

 https://dev.mysql.com/doc/refman/8.0/en/using-systemd.html

again, seems like this detail is missing.

Creating doc bug to have this added to docs.
[3 Jun 2020 16:34] Peter VARGA
Dear Terje,

@If /var/log/mysql.log is missing it will be re-created on every restart of mysql service, which is exactly what you see.

I believe we are talking about two different situations.

Again:
The file /var/log/mysql.log DOES exist and when I don't specify the log-error value THEN it remains empty AND it isn't re-created each time I restart MySQL.

I think here is a bug as log-error must be specified in order to be filled.

However, I am grateful you solved the issue and it's up to you to try to understand what I describe but it isn't what you are talking about.
[18 Jun 2020 12:36] Terje Røsten
Hi!

I might agree there more than one issues here.

When log-error option is not set in /etc/my.cnf at all 
the default for logging is standard out.

This is documented here:

  https://dev.mysql.com/doc/refman/8.0/en/error-log-destination-configuration.html

"""
If --log-error is not given, the default destination is the console. 
"""

Hence, RPM package for SLES/openSUSE ships a /etc/my.cnf with:

[mysqld]
log-error=/var/log/mysql/mysqld.log

to fix this.

However, the  mysqld systemd pre script (needed to initialize MySQL and related actions) 
defaults to /var/log/mysql.log, which is default for RHEL/Fedora systems.

$ grep /var/log /usr/bin/mysqld_pre_systemd 

log=$(get_option mysqld 'log[_-]error' "/var/log/mysql${instance:+-$instance}.log" $instance)

This default is used if log-error is absent or is in [safe_mysqld] section, this
value is not sent to mysqld process, the only side effect is that /var/log/mysql.log is
created if missing.

mysqld will 

1) if log-error is absent fall back to default and send logs to standard out.
2) if log-error is in [safe_mysqld] / [mysqld_safe] send logs to file given.
[22 Jun 2020 17:32] Peter VARGA
Thank you Terje for your very detailed explanation.

@1) if log-error is absent fall back to default and send logs to standard
out.
And here I think is the problem. For a process running in the background standard out "doesn't exist" and therefore nothing is seen in the terminal.

However, I consider it not logical under this circumstances.
[28 Jun 2021 13:57] Paul DuBois
Posted by developer:
 
Docs changes recommened by Terje have been made (do not use [mysqld_safe] / [safe_mysqld] groups in option files on systems that use systemd for server management).