Bug #3233 mysqld_safe should use basedir and/or defaults-file
Submitted: 18 Mar 2004 14:50 Modified: 10 Feb 2006 14:16
Reporter: Peter Kazmir Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:4.0.17-pro OS:Any (All)
Assigned to: CPU Architecture:Any

[18 Mar 2004 14:50] Peter Kazmir
Description:
The mysqld_safe cannot be executed unless the user is in the installation directory of the MySQL server. It would be good if mysqld_safe would read and understand when --basedir is passed to it (and/or read basedir from the appropriate section of the value passed in --defaults-file) so that one could execute mysqld_safe from any directory.

Purely an enhancement request.

Thanks!

How to repeat:
Attempt to start mysqld_safe from a directory other that <install_dir>, even if including --basedir or --defaults-file (with a valid basedir) in the command line.

Suggested fix:
Change mysqld_safe so it recognizes and uses basedir in the command-line interface arguments and so it recognizes it in the defaults file if one is specified, and possibly in the default defaults file(s) if one isn't specified.
[26 Mar 2004 3:19] Alexander Keremidarski
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.mysql.com/how-to-report.php

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

Thank you for your interest in MySQL.

Additional info:

Peter,

Can you elaborate more on "The mysqld_safe cannot be executed unless the user is in the installation directory of the MySQL server."

It always worked for me which means thousands of times within last 7 years. 

# pwd
/root
# /usr/local/mysql/bin/mysqld_safe &
[1] 24560
# Starting mysqld daemon with databases from /usr/local/mysql-4.1/var

Success.
It works from any directory.

What hapens in your case?
[26 Mar 2004 11:28] Peter Kazmir
Sorry, I didn't realize.  This is only a problem if you install MySQL somewhere OTHER THAN the default directory of /usr/local/mysql.  Say, /opt/mysql or /home/mysql.  Then it doesn't work, or, if there is another copy of MySQL installed in /usr/local/mysql, it will use files from the other installation which can produce unpredictable results.
[26 Mar 2004 14:19] Alexander Keremidarski
Ok. I understand what do you mean.

When you relocate mysql basedir you have to change defaults in mysqld_safe too because of following lines:

<mysqld_safe snippet>

# Check if this is a 'moved install directory'
elif test -f ./var/mysql/db.frm -a -f ./share/mysql/english/errmsg.sys -a \
 -x ./libexec/mysqld
then
  MY_BASEDIR_VERSION=$MY_PWD            # Where libexec, share and var are
  ledir=$MY_BASEDIR_VERSION/libexec     # Where mysqld is
  DATADIR=$MY_BASEDIR_VERSION/var
else
  MY_BASEDIR_VERSION=/usr/local/mysql-4.0
  DATADIR=/usr/local/mysql-4.0/var
  ledir=/usr/local/mysql-4.0/libexec
fi

...

# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
# and then merge with the command line arguments
if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x /usr/local/mysql-4.0/bin/my_print_defaults
then
  print_defaults="/usr/local/mysql-4.0/bin/my_print_defaults"
elif test -x /usr/local/mysql-4.0/bin/mysql_print_defaults
then
  print_defaults="/usr/local/mysql-4.0/bin/mysql_print_defaults"
else
  print_defaults="my_print_defaults"
fi

<end of snippet>

Here you can see that script always looks for MySQL instaleld in current directory. This is what you already know.

If it doesn't find MySQL it need to know where to find it and I can't imagine better way of doing it.

Basedir is set into mysqld_safe there during complie time. I deliberatly used an example of MySQL compiled with --prefix=/usr/local/mysql-4.0 to emphasise the fact that it is not hardcoded in source files.

mysqld_safe is generated from template mysqld_safe.sh in source directory.

I would not say this is a bug, but if you may have stronger arguments than mine.
[26 Mar 2004 14:39] Peter Kazmir
It's not really a bug, I agree. I was submitting it as an enhancement request...that perhaps someone can make mysqld_safe smart enough to see that I've passed --basedir=<something> and override the defaults. It's certainly not a high priority, but I hope it doesn't get closed.
[10 Feb 2006 14:16] Valeriy Kravchuk
I do not think that we need to implement this additional feature/complication for mysqld_safe script. Workaround is clearly described here. Alternatively, you can compile MySQL from sources and put into any default besedir you want.