Bug #4317 mysqld_safe assumes that my_print_defaults is going to be in certain location
Submitted: 29 Jun 2004 0:33 Modified: 29 Apr 2005 11:07
Reporter: Francisco Reinaldo Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.16 OS:All UNIX
Assigned to: Jim Winstead CPU Architecture:Any

[29 Jun 2004 0:33] Francisco Reinaldo
Description:
In mysqld_safe contains these lines of code:

if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x /usr/local/mysql/bin/my_print_defaults
then
  print_defaults="/usr/local/mysql/bin/my_print_defaults"
elif test -x /usr/local/mysql/bin/mysql_print_defaults
then
  print_defaults="/usr/local/mysql/bin/mysql_print_defaults"
else
  print_defaults="my_print_defaults"
fi

It assumes that mysqld_safe is going to be called from the mysql's installation directory which might no be true, specially is mysqld_safe is called programmatically.

How to repeat:
Install 3.x in /usr/bin, install 4.0.x in another location. Call mysqld_safe from another directory other than the installation directory (/thedir>where_mysql_is_installed/mysqld_safe &

Suggested fix:
Shouldn't it better if mysqld_safe gets the location of my_print_defaults from ledir?
[23 Jul 2004 4:36] MySQL Verification Team
Notice that when compiled with the --prefix=...., the script shows:

if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x /home/miguel/dbs/4.0/bin/my_print_defaults
then
  print_defaults="/home/miguel/dbs/4.0/bin/my_print_defaults"
elif test -x /home/miguel/dbs/4.0/bin/mysql_print_defaults
then
  print_defaults="/home/miguel/dbs/4.0/bin/mysql_print_defaults"
else
  print_defaults="my_print_defaults"
fi

then is verified the installation path. The above was created with a
source 2 days older.
[14 Feb 2005 22:54] 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".
[15 Feb 2005 11:21] Francisco Reinaldo
Miguel,

But then mysqld_safe is depedent on the compilation paramaters, isn't it?

What I am saying is that print defaults' path should be taken from ledir which is passed to mysqld_safe.
[4 Apr 2005 18:20] Michael Stassen
Except that ledir is not passed to mysqld_safe until *after* my_print_defaults is set.  It's a Catch-22:  We need ledir to find my_print_defaults, but we need my_print_defaults to find ledir.  The current setup looks in ./bin, then tries the compiled-in default, and finally trusts the PATH.  Admittedly, this is the documented behavior, but it does lead to the possibility of the wrong one being run, which in turn may result in the wrong option file being read.

I think the solution is to parse the command line args twice -- first and last.  Make one pass through the command line args at the very beginning to gather options which are needed by mysqld_safe (basedir, datadir, ledir, mysqld, mysqld-version), then use them if they're set, rather than guessing.  Parse the command line args again at the end, as we do now, to ensure they take precedence over the option files.  As a side benefit, we could then properly handle option files even when datadir has been moved.
[25 Apr 2005 23:07] Jim Winstead
The patch for this is at http://lists.mysql.com/internals/22431
[29 Apr 2005 11:07] Michael Widenius
my_print_defaults should not be searched from --ledir as this is the path where 'mysqld', not where the mysql client programs are. (my_print_defaults should be searched from --bindir, which we already do)

As the MySQL manual describes, to get mysqld_safe to work in a 'moved' installation, you must invoke it from the new installation directory.

(In theory we could as a last result try to find my_print_defaults in the same directory as mysqld_safe but I don't see this as something really critical as the current way works quiet fine)