Bug #34981 mysqld_safe should check for my_print_defaults in `dirname $0`
Submitted: 2 Mar 2008 10:02 Modified: 15 Oct 2012 13:38
Reporter: Daniël van Eeden Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0, 5.1, 5.5 OS:Linux
Assigned to: CPU Architecture:Any
Tags: Contribution, patch

[2 Mar 2008 10:02] Daniël van Eeden
Description:
mysqld_safe is not searching for my_print_defaults in `dirname $0` which is the most obvious place.

######################################################################
root@thinkpad:/data/mysql/bin# ./mysqld_safe --help
./mysqld_safe: 297: my_print_defaults: not found
./mysqld_safe: 303: my_print_defaults: not found
Usage: ./mysqld_safe [OPTIONS]
  --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
  --ledir=DIRECTORY          Look for mysqld in the specified directory
  --open-files-limit=LIMIT   Limit the number of open files
  --core-file-size=LIMIT     Limit core files to the specified size
  --timezone=TZ              Set the system timezone
  --mysqld=FILE              Use the specified file as mysqld
  --mysqld-version=VERSION   Use "mysqld-VERSION" as mysqld
  --nice=NICE                Set the scheduling priority of mysqld
  --skip-kill-mysqld         Don't try to kill stray mysqld processes
  --syslog                   Log messages to syslog with 'logger'
  --skip-syslog              Log messages to error log (default)
  --syslog-tag=TAG           Pass -t "mysqld-TAG" to 'logger'

All other options are passed to the mysqld program.
######################################################################

How to repeat:
untar the mysql binary tarball in a random location and run "./mysqld --help" from $untar_location/bin/

Suggested fix:
--- mysqld_safe.orig    2008-03-02 10:47:54.966155645 +0100
+++ mysqld_safe 2008-03-02 10:53:06.971438121 +0100
@@ -274,7 +274,10 @@
 
 # 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
+if test -x `dirname $0`/my_print_defaults
+then 
+  print_defaults="`dirname $0`/my_print_defaults"
+elif test -x ./bin/my_print_defaults
 then
   print_defaults="./bin/my_print_defaults"
 elif test -x /usr/local/mysql/bin/my_print_defaults
[3 Mar 2008 14:43] Sveta Smirnova
Thank you for the report.

Verified as described.
[3 Mar 2008 21:17] Omer Barnir
workaround: cd to 'basedir' and run ./bin/mysqld_safe to avoid the issue
[2 Oct 2008 17:23] Jim Winstead
Sorry for bouncing this contribution around, but mysqld_safe is considered part of the server, not a command-line tool. Re-categorizing so it catches the eye of the right people.
[30 Dec 2010 13:13] Daniël van Eeden
This also seems to cause problems for Upstart on Ubuntu Linux.

http://karlssonondatabases.blogspot.com/2010/12/ubuntu-upstart-for-automatic-mysql.html
[3 Jan 2011 10:42] Daniël van Eeden
Updated version field
[16 Jul 2012 10:25] shalini P S
Even i am facing the same issue. please help
[16 Jul 2012 10:29] shalini P S
Extracted the tar , and unable to even mysqld_safe getting this following error please help

ERROR:
./mysqld_safe: line 487: my_print_defaults: command not found
./mysqld_safe: line 493: my_print_defaults: command not found
120714 03:32:39 mysqld_safe Logging to '/datadir/*.err'.
touch: cannot touch `/datadir/*.err': No such file or directory
chown: `mysql': invalid user
120714 03:32:39 mysqld_safe The file /usr/local/mysql/bin/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
./mysqld_safe: line 107: /datadir/*.err: No such file or directory
[16 Jul 2012 10:32] shalini P S
which basedir
/usr/bin/which: no basedir in (/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[15 Oct 2012 13:38] Erlend Dahl
Fixed in 5.5.19.