Bug #898 init.d mysql.server has problems with non-standard install location
Submitted: 23 Jul 2003 7:43 Modified: 4 Aug 2004 14:05
Reporter: James Ponder Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:3.23.57 OS:Linux (Linux SuSE SLES 8)
Assigned to: Lenz Grimmer CPU Architecture:Any

[23 Jul 2003 7:43] James Ponder
Description:
The comments in mysql.server suggest having an /etc/my.cnf file with a basedir setting.  This does not work because mysql.server does not honour this directive when calculating the datadir and the pid file locations.

To actually get mysql.server to work you need to specify basedir, datadir and pid_file all using absolute filenames.  This negates the nice pid_file calculation-based-on-hostname abilities of mysql.server.

How to repeat:
Install mysql to a non-standard location (not /usr/local/mysql) and try using the mysql.server script.

Suggested fix:
This is a patch to move the pid_file calculation to later on after the my.cnf file has been processed.  This is very simple.  It doesn't fix the datadir problem, meaning that the documentation at the start should say to set BOTH basedir and datadir.

--- support-files/mysql.server  2003-06-06 16:03:50.000000000 +0100
+++ /etc/init.d/mysql.server    2003-07-23 15:18:05.000000000 +0100
@@ -57,16 +57,6 @@
 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
 export PATH
 
-if test -z "$pid_file"
-then
-  pid_file=$datadir/`/bin/hostname`.pid
-else
-  case "$pid_file" in
-    /* ) ;;
-    * )  pid_file="$datadir/$pid_file" ;;
-  esac
-fi
-
 mode=$1    # start or stop
 
 parse_arguments() {
@@ -120,6 +110,16 @@
 
 parse_arguments `$print_defaults mysqld mysql_server mysql.server`
 
+if test -z "$pid_file"
+then
+  pid_file=$datadir/`/bin/hostname`.pid
+else
+  case "$pid_file" in
+    /* ) ;;
+    * )  pid_file="$datadir/$pid_file" ;;
+  esac
+fi
+
 # Safeguard (relative paths, core dumps..)
 cd $basedir
 
Here however, is a more radical change, this tidies things up and does things in a sensible order allowing just basedir to be set in my.cnf and now this does affect datadir and pid_file all properly.

--- support-files/mysql.server  2003-06-06 16:03:50.000000000 +0100
+++ /etc/init.d/mysql.server    2003-07-23 15:39:38.000000000 +0100
@@ -33,39 +33,15 @@
 #   basedir=<path-to-mysql-installation-directory>
 # - Add the above to any other configuration file (for example ~/.my.ini)
 #   and copy my_print_defaults to /usr/bin
-# - Add the path to the mysql-installation-directory to the basedir variable
-#   below.
+# - Add the path to the mysql-installation-directory to the default_basedir
+#   variable below.
 #
 # If you want to affect other MySQL variables, you should make your changes
 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
 
-basedir=
-
 # The following variables are only set for letting mysql.server find things.
-
-# Set some defaults
-datadir=/usr/local/mysql/data
-pid_file=
-if test -z "$basedir"
-then
-  basedir=/usr/local/mysql
-  bindir=./bin
-else
-  bindir="$basedir/bin"
-fi
-
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
-export PATH
-
-if test -z "$pid_file"
-then
-  pid_file=$datadir/`/bin/hostname`.pid
-else
-  case "$pid_file" in
-    /* ) ;;
-    * )  pid_file="$datadir/$pid_file" ;;
-  esac
-fi
+default_basedir=/usr/local/mysql
+default_datadir=$default_basedir/data
 
 mode=$1    # start or stop
 
@@ -84,12 +60,6 @@
 if test -x ./bin/my_print_defaults
 then
   print_defaults="./bin/my_print_defaults"
-elif test -x $bindir/my_print_defaults
-then
-  print_defaults="$bindir/my_print_defaults"
-elif test -x $bindir/mysql_print_defaults
-then
-  print_defaults="$bindir/mysql_print_defaults"
 else
   # Try to find basedir in /etc/my.cnf
   conf=/etc/my.cnf
@@ -118,8 +88,28 @@
   test -z "$print_defaults" && print_defaults="my_print_defaults"
 fi
 
+basedir=
+
 parse_arguments `$print_defaults mysqld mysql_server mysql.server`
 
+if test -n "$basedir"; then
+  default_datadir=$basedir/data
+fi
+
+test -z "$datadir" && datadir=$default_datadir
+
+if test -z "$pid_file"
+then
+  pid_file=$datadir/`/bin/hostname`.pid
+else
+  case "$pid_file" in
+    /* ) ;;
+    * )  pid_file="$datadir/$pid_file" ;;
+  esac
+fi
+
+bindir=$basedir/bin
+
 # Safeguard (relative paths, core dumps..)
 cd $basedir
[23 Jul 2003 8:22] James Ponder
A better diff file:

--- support-files/mysql.server  2003-06-06 16:03:50.000000000 +0100
+++ /etc/init.d/mysql.server    2003-07-23 16:21:31.000000000 +0100
@@ -33,39 +33,15 @@
 #   basedir=<path-to-mysql-installation-directory>
 # - Add the above to any other configuration file (for example ~/.my.ini)
 #   and copy my_print_defaults to /usr/bin
-# - Add the path to the mysql-installation-directory to the basedir variable
-#   below.
+# - Add the path to the mysql-installation-directory to the default_basedir
+#   variable below.
 #
 # If you want to affect other MySQL variables, you should make your changes
 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
 
-basedir=
-
 # The following variables are only set for letting mysql.server find things.
-
-# Set some defaults
-datadir=/usr/local/mysql/data
-pid_file=
-if test -z "$basedir"
-then
-  basedir=/usr/local/mysql
-  bindir=./bin
-else
-  bindir="$basedir/bin"
-fi
-
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
-export PATH
-
-if test -z "$pid_file"
-then
-  pid_file=$datadir/`/bin/hostname`.pid
-else
-  case "$pid_file" in
-    /* ) ;;
-    * )  pid_file="$datadir/$pid_file" ;;
-  esac
-fi
+default_basedir=/usr/local/mysql
+default_datadir=$default_basedir/data
 
 mode=$1    # start or stop
 
@@ -81,15 +57,10 @@
 
 # Get arguments from the my.cnf file,
 # groups [mysqld] [mysql_server] and [mysql.server]
-if test -x ./bin/my_print_defaults
-then
+if test -x ./bin/my_print_defaults; then
   print_defaults="./bin/my_print_defaults"
-elif test -x $bindir/my_print_defaults
-then
-  print_defaults="$bindir/my_print_defaults"
-elif test -x $bindir/mysql_print_defaults
-then
-  print_defaults="$bindir/mysql_print_defaults"
+elif test -x ./bin/mysql_print_defaults; then
+  print_defaults="./bin/mysql_print_defaults"
 else
   # Try to find basedir in /etc/my.cnf
   conf=/etc/my.cnf
@@ -118,8 +89,36 @@
   test -z "$print_defaults" && print_defaults="my_print_defaults"
 fi
 
+basedir=
+
 parse_arguments `$print_defaults mysqld mysql_server mysql.server`
 
+if test -n "$basedir"; then
+  default_datadir=$basedir/data
+fi
+
+test -z "$basedir" && basedir=$default_basedir
+test -z "$datadir" && datadir=$default_datadir
+
+if test -z "$pid_file"
+then
+  pid_file=$datadir/`/bin/hostname`.pid
+else
+  case "$pid_file" in
+    /* ) ;;
+    * )  pid_file="$datadir/$pid_file" ;;
+  esac
+fi
+
+if test ! -d "$basedir"; then
+  echo "The base directory '$basedir' does not exist."
+  echo "If your MySQL is installed in another location, please configure your"
+  echo "/etc/my.cnf file."
+  exit 2
+fi
+
+bindir=$basedir/bin
+
 # Safeguard (relative paths, core dumps..)
 cd $basedir
 
@@ -170,7 +169,7 @@
         rm /var/lock/subsys/mysql
       fi
     else
-      echo "No mysqld pid file found. Looked for $pid_file."
+      echo "No mysqld pid file found at $pid_file."
     fi
     ;;
[29 Jul 2003 12:40] Lenz Grimmer
Thanks for your suggestions - I will look into them.
[4 Aug 2004 14:05] Lenz Grimmer
A similar fix to this one has been applied to the 4.0 mysql.server startup script by now - it will not be
fixed for 3.23.