Bug #96896 mysqld_safe doen't respect UMASK when creating MySQL Error Log.
Submitted: 17 Sep 2019 6:20 Modified: 2 Oct 2019 15:33
Reporter: Meiji Kimura Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.6.45 OS:Any
Assigned to: CPU Architecture:Any

[17 Sep 2019 6:20] Meiji Kimura
Description:
We can change default permission for file, and directories with UMASK, UMASK_DIR

https://dev.mysql.com/doc/refman/5.6/en/setting-environment-variables.html
https://dev.mysql.com/doc/refman/5.6/en/environment-variables.html

mysqld works well, but mysqld_safe doesn't respect when creating MySQL Error Log (there is no file for it).

https://dev.mysql.com/doc/refman/5.6/en/environment-variables.html

UMASK=0644
export UMASK
./mysqld_safe &

The result is here.

-rw-r-----. 1 meiji meiji 473  9月 12 17:09 error.log
-rw-r--r--. 1 meiji meiji 210  9月 12 17:09 slow.log

slow.log is created by mysqld, so 0644, but 
error.log (there is no file) mysqld_safe created it with 0640, doesn't respect UMASK setting.

After removing error.log, and issue 'flush error log', it become like these.

-rw-r--r--. 1 meiji meiji 473  9月 12 17:11 error.log
-rw-r--r--. 1 meiji meiji 210  9月 12 17:09 slow.log

Because error.log is re-created by mysqld, not mysqld_safe.

How to repeat:
Use taball, and initialize, and delete error.log, and activate mysqld via mysqld_safe.

Suggested fix:
mysqld should respect UMASK for the first time to create MySQL error log.
[17 Sep 2019 7:13] MySQL Verification Team
Hello Meiji-San,

Thank you for the report and steps.
Verified as described with 5.6.45 build.

regards,
Umesh
[17 Sep 2019 8:15] Terje Røsten
Due to various problems in mysqld_safe and stronger focus on robustness and the fact that this script might be run by privileged user, default umask is hard coded and set to strict value 0137. This will not change.

The workaround is simple: create the file with wanted properties *before* mysqld_safe is executed.

A documentation update is required.
[17 Sep 2019 8:17] MySQL Verification Team
Thank you, Terje.

regards,
Umesh
[2 Oct 2019 15:33] Paul DuBois
Posted by developer:
 
Added a note to https://dev.mysql.com/doc/refman/8.0/en/file-permissions.html:

An exception applies for the error log file if you start mysqld using
mysqld_safe, which does not respect UMASK: mysqld_safe may create the
error log file if it does not exist prior to starting mysqld, and
mysqld_safe uses a umask set to a strict value of 0137. If this is
unsuitable, create the error file manually with the desired access
mode prior to executing mysqld_safe.

And added a cross reference for that section to
https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html.