Bug #56010 Spaces cause mysqld_safe not to start,my_print_defaults generated invalid output
Submitted: 16 Aug 2010 12:20 Modified: 3 Sep 2010 15:04
Reporter: P Lekensteyn Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.49, 4.1, 5.0, 5.1, 5.6.99 OS:Linux (Debian Lenny)
Assigned to: CPU Architecture:Any
Tags: Contribution, my_print_defaults, mysqld_safe, spaces

[16 Aug 2010 12:20] P Lekensteyn
Description:
At some points, MySQL fails to quote parameters.
This implies that parameters with spaces within it generates errors in scripts (mysqld_safe)
and invalid output (my_print_defaults)

How to repeat:
Have MySQL installed in a directory with spaces in a folders name, for example '/opt/web server/mysql'.
"/opt/web server/etc/my.cnf" contains my-medium.cnf, with the appropriate "basedir", "tmpdir", "socket" and "datadir" set.

Now execute:
# "/opt/web server/mysql/bin/mysqld_safe" "--defaults-file=/opt/web server/etc/my.cnf"

Result:
mysql/bin/mysqld_safe: line 252: test: /opt/web: binary operator expected
mysql/bin/mysqld_safe: line 260: test: /opt/web: binary operator expected
mysql/bin/mysqld_safe: line 265: svr/mysql/var: No such file or directory
mysql/bin/mysqld_safe: line 316: /opt/web: is a directory
mysql/bin/mysqld_safe: line 322: /opt/web: is a directory
100816 15:50:21 mysqld_safe Logging to '/debian.err'.
chown: invalid user: `mysql'
100816 15:50:21 mysqld_safe The file /opt/web svr/mysql/libexec/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

$ "/opt/web server/mysql/bin/my_print_defaults" "--defaults-file=/opt/web server/mysql/etc/my.cnf" mysqld

Result:
--basedir=/opt/web server/mysql
--datadir=/opt/web server/mysql/var/mysql
--tmpdir=/opt/web server/tmp
--language=/opt/web server/mysql/share/english
--user=nobody
--port=3306
--socket=/opt/web server/tmp/mysql.sock
--skip-external-locking
--key_buffer_size=16M
--max_allowed_packet=1M
--table_open_cache=64
--sort_buffer_size=512K
--net_buffer_length=8K
--read_buffer_size=256K
--read_rnd_buffer_size=512K
--myisam_sort_buffer_size=8M
--character-set-server=utf8
--collation-server=utf8_general_ci

Suggested fix:
Patch for mysqld_safe.sh will be included later.

Suggested fix for my_print_defaults: single-quote all parameters returned by my_print_defaults.
[16 Aug 2010 12:21] P Lekensteyn
Patch file for scripts/mysqld_safe.sh, based on MySQL 5.1.49

Attachment: mysqld_safe.sh.patch (text/x-diff), 2.32 KiB.

[16 Aug 2010 13:57] P Lekensteyn
A temporary fix in mysqld_safe for my_print_defaults.
Insert the following between 'parse_arguments `"$print_defaults" "$defaults" --loose-verbose mysqld server' and the last backtick:
|sed -e "s,',$BACKSLASH'," -e "s,.*,'\0',"

And define BACKSLASH='\\' above that (dash and bash does not need the same amount of backslashes between backticks)

(line 316 and 322)
[16 Aug 2010 14:27] P Lekensteyn
Ignore my last comment, it's causing all options to be ignored.
[16 Aug 2010 18:31] Sveta Smirnova
Thank you for the report.

Verified as described.
[17 Aug 2010 11:29] P Lekensteyn
Patch for mysqld_safe, parse arguments line by line

Attachment: mysqld_safe.sh-print_defaults.patch (text/x-diff), 902 bytes.

[23 Aug 2010 13:08] P Lekensteyn
Patch for mysqld_safe, parse_arguments line by line and import variables in local scope. The old patch wasn't working fully.

Attachment: mysqld_safe-print_defaults-rv2.patch (text/x-diff), 921 bytes.

[3 Sep 2010 15:04] P Lekensteyn
My last patch did not satisfy fully.
IFS=`echo` does not work.
It should be replaced with:

IFS='
'