Bug #83060 Can't log errors to a symbolic link
Submitted: 20 Sep 2016 11:48 Modified: 3 Oct 2016 11:47
Reporter: Matthias Burtscher Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.7.15 OS:Ubuntu
Assigned to: CPU Architecture:Any

[20 Sep 2016 11:48] Matthias Burtscher
Description:
In previous versions you could log errors to a symbolic link. This was also suggested in case you want to log to `/dev/stderr` which is not possible due to the lack of a file extension.

However, since 5.7.15 you cannot log to a symbolic link at all. It does not matter if the link points to a regular file or `/dev/stderr`. The MySQL server will stop immediately without providing an error message:

Output of reproduction steps:

2016-09-20T11:47:35.523807Z mysqld_safe Logging to '/tmp/test.err'.
2016-09-20T11:47:35.533142Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2016-09-20T11:47:35.687183Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

How to repeat:
1. Create a log file `touch /tmp/test`
2. Create a symlink `ln -s /tmp/test /tmp/test.err`
3. Start MySQL using `mysqld_safe --log-error=/tmp/test.err`
[20 Sep 2016 11:49] Matthias Burtscher
Using a symbolic link has previously been suggested here:

https://bugs.mysql.com/bug.php?id=57690
[21 Sep 2016 10:12] MySQL Verification Team
Hello Matthias,

Thank you for the report.
I quickly tried with the binary tarball but not seeing the reported issue"

rm -rf 83051
bin/mysqld --initialize-insecure --basedir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15 --datadir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051 -v

bin/mysqld_safe --basedir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15 --datadir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051 --core-file --socket=/tmp/mysql_ushastry.sock --pid-file=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051/host.pid --port=3306 --log-error=/tmp/test.err 2>&1 &

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: 2016-09-21T07:40:41.410324Z mysqld_safe Logging to '/tmp/test.err'.
2016-09-21T07:40:41.439459Z mysqld_safe Starting mysqld daemon with databases from /export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: bin/mysql -uroot -S /tmp/mysql_ushastry.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q
Bye
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: ls -l /tmp/test.err
-rw-r----- 1 umshastr common 3818 Sep 21 09:40 /tmp/test.err

-- bring down Server
-- 

rm -rf /tmp/test.err
touch /tmp/test
ln -s /tmp/test /tmp/test.err

-- Start Server

bin/mysqld_safe --basedir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15 --datadir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051 --core-file --socket=/tmp/mysql_ushastry.sock --pid-file=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051/host.pid --port=3306 --log-error=/tmp/log.err 2>&1 &

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: 2016-09-21T07:42:06.104132Z mysqld_safe Logging to '/tmp/log.err'.
2016-09-21T07:42:06.133751Z mysqld_safe Starting mysqld daemon with databases from /export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: bin/mysql -uroot -S /tmp/mysql_ushastry.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q
Bye
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: ls -l /tmp/test*
-rw-r--r-- 1 umshastr common 0 Sep 21 09:42 /tmp/test
lrwxrwxrwx 1 umshastr common 9 Sep 21 09:42 /tmp/test.err -> /tmp/test
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15:

If you can provide more information, feel free to add it to this bug and change the status back to 'Open'.

Thanks,
Umesh
[21 Sep 2016 14:50] Matthias Burtscher
I'm not 100% sure if you used the right code. In your second launch scenario you used `log.err` file although the link was created at `test.err`.

Howevery I ran the following tests again:

Ubuntu Docker
=============

1. docker run ubuntu:latest /bin/bash
2. root: apt update && apt install mysql-server
3. root: touch /tmp/test.err
4. root: ln -s /tmp/test.err /tmp/test-link.err
5. root: mysqld_safe --log-error=/tmp/test-link.err
6. root: mysqld --log-error=/tmp/test-link.err

Both launch scenarios (5/6) crash immediately without an error message.

Ubuntu Docker from Website
==========================

1. docker run ubuntu:latest /bin/bash
2. root: cd /tmp
3. root: wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.15-1ubuntu16.04_amd64.deb-bu...
4. root: tar -xpf mysql-server_5.7.15-1ubuntu16.04_amd64.deb-bundle.tar
5. root: dpkg -i *.deb
6. root: apt install -f
7. root: touch /tmp/test.err
8. root: ln -s /tmp/test.err /tmp/test-link.err
9. root: mkdir /tmp/data
10. root: mysqld_safe --user=root --data-dir=/tmp/data --log-error=/tmp/test-link.err
11: root: mysqld --user=root --data-dir=/tmp/data --log-error=/tmp/test-link.err

This scenario works fine.

So it seems that it's some kind of configuration/packaging issue with Ubuntu's default setup.
[21 Sep 2016 15:15] Terje Røsten
Hi!

Try to set correct owner of log file before starting:

Ubuntu Docker
=============

1. docker run ubuntu:latest /bin/bash
2. root: apt update && apt install mysql-server
3. root: touch /tmp/test.err
  
   root: chown mysql:mysql /tmp/test.err

4. root: ln -s /tmp/test.err /tmp/test-link.err
5. root: mysqld_safe --log-error=/tmp/test-link.err
6. root: mysqld --log-error=/tmp/test-link.err
[22 Sep 2016 9:30] MySQL Verification Team
Looks like I pasted wrong one, still no issues even after changing.
Surely some other issue(pri etc) causing problem, please try as Terje suggested.
--

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: rm -rf /tmp/test.err
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: touch /tmp/test
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: ln -s /tmp/test /tmp/test.err
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: bin/mysqld_safe --basedir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15 --datadir=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051 --core-file --socket=/tmp/mysql_ushastry.sock --pid-file=/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051/host.pid --port=3306 --log-error=/tmp/test.err 2>&1 &
[1] 8908
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: 2016-09-22T09:25:43.750386Z mysqld_safe Logging to '/tmp/test.err'.
2016-09-22T09:25:43.778049Z mysqld_safe Starting mysqld daemon with databases from /export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15/83051

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15:
[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: ls -l /tmp/test*
-rw-r--r-- 1 umshastr common 3817 Sep 22 11:25 /tmp/test
lrwxrwxrwx 1 umshastr common    9 Sep 22 11:25 /tmp/test.err -> /tmp/test

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.15: bin/mysql -uroot -S /tmp/mysql_ushastry.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
[22 Sep 2016 11:12] Matthias Burtscher
I tried this one, still doesn't work…

1. docker run -it ubuntu:latest /bin/bash
2. root: apt update && apt install mysql-server
3. root: touch /tmp/test.err
4. root: chown mysql:mysql /tmp/test.err
5. root: ln -s /tmp/test.err /tmp/test-link.err
6. root: mysqld --log-error=/tmp/test-link.err
[27 Sep 2016 10:18] Lars Tangvald
What didn't work? I tried your commands and the server fails to start because /var/run/mysqld doesn't exist (it's created by the service in Debian/Ubuntu), but the log contents are there.

Creating /var/run/mysqld and chowning it to mysql:mysql made the server start successfully in the container.
[27 Sep 2016 11:08] Lars Tangvald
To clarify, try the following:

1. docker run -it ubuntu:latest /bin/bash
2. root: apt update && apt install mysql-server
3. root: touch /tmp/test.err
4. root: chown mysql:mysql /tmp/test.err
5. root: ln -s /tmp/test.err /tmp/test-link.err
6. root: mkdir /var/run/mysqld && chown mysql:mysql /var/run/mysqld
7. root: mysqld --log-error=/tmp/test-link.err

You could also specifiy --socket and --pid-file to some other location
[3 Oct 2016 11:47] Matthias Burtscher
Umm, it seems you're right – I didn't see that.

Should I've been able to see an error message somewhere? There was no output neither in stdout nor in stderr.