Bug #11192 mysqld_safe only evaluates --defaults-file option when it is the first option
Submitted: 9 Jun 2005 5:03 Modified: 14 Feb 2017 8:39
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.x, 5.x OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[9 Jun 2005 5:03] [ name withheld ]
Description:
When you want to pass a configuration file to mysqld_safe via --defaults-file it has to be the first option in the argument list.
e.g. mysqld_safe --basedir=/opt/mysql --defaults-file=/opt/databases/3333/my.cnf --ledir=/opt/mysql/bin
Does not use the specified configuration file, but
mysqld_safe  --defaults-file=/opt/databases/3333/my.cnf --basedir=/opt/mysql --ledir=/opt/mysql/bin
does.

How to repeat:
install mysql into e.g. /opt/mysql, a database into e.g. /opt/database/3333/my.cnf
and excute the statements above.
The first one will print:

touch: cannot touch `/usr/local/mysql/data/localhost.err': No such file or directory
chown: cannot access `/usr/local/mysql/data/localhost.err': No such file or directory
Starting mysqld daemon with databases from /usr/local/mysql/data
/opt/WeatherscapeXT/mysql/bin/mysqld_safe: line 311: /usr/local/mysql/data/localhost.err: No such file or directory
/opt/WeatherscapeXT/mysql/bin/mysqld_safe: line 1: /usr/local/mysql/data/localhost.err: No such file or directory
STOPPING server from pid file /usr/local/mysql/data/localhost.pid
tee: /usr/local/mysql/data/localhost.err: No such file or directory
050609 16:58:13  mysqld ended
tee: /usr/local/mysql/data/localhost.err: No such file or directory

because it uses the build in path instead of the one as set in the config file. The second call works as expected.

Suggested fix:
At least mention it in the documentation:)
Or fix the mysqld_safe script so it does not only check if the first argument is --no-defaults or --defaults-file or --defaults-extra-file.
[9 Jun 2005 11:55] MySQL Verification Team
This is the expected behavior and in several places is mentioned
on the manual i.e::

http://dev.mysql.com/doc/mysql/en/innodb-configuration.html

........

If you want to make sure that mysqld reads options only from a specific file, you can use the --defaults-option as the first option on the command line when starting the server:

......
[9 Jun 2005 21:46] [ name withheld ]
Fair enough.
But I would expect this behaviour to be mentioned in the documentation for mysqd_safe.
That's the page, I looked up to figure out what my problem is.
After all, if I am not using InnoDB, why should I look at the InnoDB configuration documentation.
No biggy, but such little things can be annoying. I would have had to search your whole site to find the required information, would I not have been able to understand the shell script code in mysqld_safe, to find the cause of the problem.

Anyway, it's a great database.

Frank
[8 Dec 2009 3:55] Roel Van de Paar
'This must be the first option on the command line if it is used.'
http://dev.mysql.com/doc/refman/5.1/en/mysqld-safe.html#option_mysqld_safe_defaults-file

Can we also include this in the --help option?

Usage: ./mysqld_safe [OPTIONS]
  --defaults-file=FILE       Use the specified defaults file
  --defaults-extra-file=FILE Also use defaults from the specified file

It is currently listed as a standard option, not specifying it should be used as the first option.
[3 Oct 2014 10:09] Hartmut Holzgraefe
the "mysql" and "mysqladmin" command line tools (and others like "mysqlbinlog" probably also) list these options in an extra section at the end of the options list in --help output:

  [... list of regular options ...]

  Default options are read from the following files in the given order:
  /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql-5.6.20/etc/my.cnf ~/.my.cnf 
  The following groups are read: mysql client
  The following options may be given as the first argument:
  --print-defaults        Print the program argument list and exit.
  --no-defaults           Don't read default options from any option file,
                          except for login file.
  --defaults-file=#       Only read default options from the given file #.
  --defaults-extra-file=# Read this file after the global files are read.
  --defaults-group-suffix=#

"mysqld_save" (which as a shell script doesn't use the default cmdline parser from libmysqlclient) just prints them intermixed with other options ... should have them separate the same way as the compiled command line tools do ...
[14 Feb 2017 8:38] Terje Røsten
Posted by developer:
 
mysqld_safe --help now prints:

Usage: bin/mysqld_safe [OPTIONS]
 The following options may be given as the first argument:
  --no-defaults              Don't read the system defaults file
  --defaults-file=FILE       Use the specified defaults file
  --defaults-extra-file=FILE Also use defaults from the specified file

 Other options:
  --ledir=DIRECTORY          Look for mysqld in the specified directory

Docs: 

 https://dev.mysql.com/doc/refman/5.5/en/mysqld-safe.html 

also includes link to 

 https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html

which describe special treatment of these options.

(Change was done with fix of Bug#83937/Bug#25144379).
[15 Feb 2017 1:13] Paul DuBois
Posted by developer:
 
Noted in 5.5.55, 5.6.36, 5.7.18, 8.0.1 changelogs.

The --help message for mysqld_safe was corrected to mention that the
--no-defaults, --defaults-file, and --defaults-extra-file options, if
given, must be the first argument.