Bug #26033 Cannot use directories that contain spaces in my.cnf
Submitted: 2 Feb 2007 0:53 Modified: 1 Jul 2013 18:46
Reporter: Ben J Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.0.24a-Debian_9-log (Ubuntu .deb Pkg) OS:Linux (Ubuntu Linux 6.10 64-bit)
Assigned to: Assigned Account CPU Architecture:Any

[2 Feb 2007 0:53] Ben J
Description:
If the user attempts to set certain directives within my.cnf to values that contain spaces, such as directories with spaces, the MySQL server will not start.

More specifically, if the user attempts to set the value of the "datadir" directive to a directory that contains spaces in its path, the MySQL server will not start. This problem occurs whether the path that contains spaces is enclosed in single quotes, double quotes, or no quotes at all. This problem also occurs if the spaces are escaped with a single backslash ( \ ) or \s, as suggested in the MySQL 5.0 documentation (with or without the aforementioned types of quotes).

If this is by design and MySQL users on *NIX platforms are not permitted to use spaces in path names, the documentation should contain a prominent warning about this. Windows users can certainly configure my.ini with path names that contain spaces, so it is surprising if this behavior is intentional.

About 1/3 of the way down the relevant manual page ( http://dev.mysql.com/doc/refman/5.0/...ion-files.html ) there is mention of the proper syntax for the values in question, and manual specifically states, "You can enclose the value within single quotes or double quotes, which is useful if the value contains a ‘#’ comment character or whitespace." This does not seem to work, however.

How to repeat:
Use a my.cnf file that contains only the following data (take note of the space in the "datadir" value):

###########################################
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /home/user/MySQL Data/
tmpdir = /tmp
###########################################

When I try to start the server using

$ sudo /etc/init.d/mysql start

I receive the following error message:

df: `/home/username/MySQL/.': No such file or directory
* /etc/init.d/mysql: ERROR: The partition with /home/user/MySQL is too full!

Suggested fix:
Clearly, MySQL is misinterpreting the space in the path name, as evidenced by the fact that the error message contains the path name, but is truncated at the first occurrence of the space character.

If this is in fact a bug, then the fix should be obvious.

If this is not a bug, then I suggest doing two things:

1.) Update the documentation such that it clearly states that using spaces in my.cnf path names is not permitted on UNIX-like systems.

2.) Update the error message that MySQL produces in this case. What appears to be happening is that MySQL cannot find the specific path (due to misinterpreting the space character(s)) and throws an error about the partition being full, instead of "not found". Obviously, the partition is not full.
[2 Feb 2007 0:59] Ben J
I accidentally forgot to change one of the path names in the error message (I modified the original error message because I did not want to expose the real path names of my machine). In keeping with the original my.cnf snippet I posted, this would have been the error message:

df: `/home/user/MySQL/.': No such file or directory
* /etc/init.d/mysql: ERROR: The partition with /home/user/MySQL is too full!
[2 Feb 2007 1:02] Ben J
I realize now that the "partition full" error is being thrown by the daemon, not MySQL itself. MySQL is reporting the correct error, which is that the directory was not found (even though the directory SHOULD have been found).
[2 Feb 2007 9:10] Sveta Smirnova
Thank you for the report.

I can not repeat it using current development sources and starting mysqld as `libexec/mysqld --defaults-file=./my.cnf`

Please try using current 5.0.33 version with and without mysql.server script and say us results.
[3 Mar 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[28 Sep 2007 21:36] FGF Emperor
I'm having the same issue here. My MySQL version is 5.0.45-1.

From the LOG:

070928 18:26:29  mysqld started
/usr/libexec/mysqld: Too many arguments (first extra is 'Datafiles').
Use --help to get a list of available options
070928 18:26:29  mysqld ended

From my.cnf:

datadir="/mnt/Najara/MySQL Datafiles"

It also happens with:
datadir='/mnt/Najara/MySQL Datafiles'
datadir=/mnt/Najara/MySQL\ Datafiles
datadir=/mnt/Najara/MySQL\sDatafiles

Any suggestions?
[10 Oct 2007 7:43] Sveta Smirnova
FGF Emperor,

thank you for the feedback. Which tool do you use to start MySQL server?
[11 Oct 2007 19:46] FGF Emperor
I'm not using any tool actually...
Just "service mysqld start" ...
[22 Feb 2008 21:02] Sveta Smirnova
Thank you for the feedback.

Verified as described. To repeat use mysql.server to start mysqld
[16 Mar 2009 12:04] Daniel Fischer
This bug does not appear to exist in this form in MySQL 5.1 and above. However, other scripts, most notably mysql_install_db, are easily confused by blanks in paths in my.cnf, e.g. set datadir="foo bar" in my cnf, run mysql_install_db --defaults-file=..., and the datadir will be created in "foo".
[6 Oct 2012 20:18] Tristan Perich
I can confirm that as of MySQL 5.5.28 on MacOS X (currently using 10.6.8), using spaces in datadir does not start up. Tested all variants: enclosed in single or double quotes, escaped as \s (with and without quotes). (For validation, I changed all spaces to underscores and MySQL starts up properly.)
[1 Jul 2013 18:46] Ben J
6.5 years have elapsed since I filed this bug report.

What is the status of this report? Commenter Daniel Fischer reports that the issue is fixed in 5.1. Please update this ticket if that assertion is true.
[23 Sep 2013 23:24] Gabriel Gaster
I can confirm that as of MySQL 5.6.13 on MacOS X (currently using 10.8.4), using spaces in datadir does not start up. Tested all variants: enclosed in single or double quotes, escaped as \s (with and without quotes). (For validation, I changed all spaces to underscores and MySQL starts up properly.)

However -- there is a workaround here: http://stackoverflow.com/a/13317794/1044561.
[4 Oct 2014 16:39] Daniel Noriega
too sad, this bug have 5 years and no body seems like could fix it... is much to ask that the users can use spaces for datadir???
[16 May 2015 4:38] David Dixon
Here it is, May 2015, still a bug.
[3 Jan 2020 4:39] C D Tavares
Still a problem on MySQL 8.0.18. Wow.
[5 Jul 2021 22:46] Pedro Ferreira
To those still facing this issue on MySQL 8 I'd like to share with you how to "fix" it:

The problem is not that the configuration file does not accept spaces.
You can accomplish this by adding the path between single quotes (').

The problem is actually the permissions of the path you desire to set as the datadir.
What you need to do is make sure mysql is the owner of the path you wish to use.
To accomplish this you can simply use sudo chown -r mysql:mysql <path>.

TLDR:
Add the directory you want as datadir to the .cnf file using single quotes and make sure mysql owns the desired directory.

MySQL version: 8.0.25