Bug #3530 Binary install fails to start with non-default basedir and datadir
Submitted: 21 Apr 2004 15:24 Modified: 28 Apr 2004 16:15
Reporter: C Evans Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:4.0.18 (Solaris/SPARC binary) OS:Solaris (Solaris 9)
Assigned to: Michael Widenius CPU Architecture:Any

[21 Apr 2004 15:24] C Evans
Description:
The Documentation states that mysql can run from non-default install and data
directories. However the mysqld_safe script fails to honour this, and will fail if both the install and data directories are non-default.

Note: Bug #898 is related

How to repeat:
* Install mysql, install directory = /local/opt/mysql

* Move the data directory and all content to /export/home/mysql/data

* Create a /etc/my.cnf file containing the following custom lines:

  basedir = /local/opt/mysql
  datadir= /export/home/mysql/data

When the user tries to run MySQL, (using a wrapper that does "cd /local/opt/mysql") the following lines in mysqld_safe apparently fail to honour the config in my.cnf-

MY_PWD=`pwd`
# Check if we are starting this relative (for the binary release)
if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a
\
 -x ./bin/mysqld
then
  MY_BASEDIR_VERSION=$MY_PWD  # Where bin, share and data are
  ledir=$MY_BASEDIR_VERSION/bin  # Where mysqld is
  DATADIR=$MY_BASEDIR_VERSION/data
  if test -z "$defaults"
  then
    defaults="--defaults-extra-file=$MY_BASEDIR_VERSION/data/my.cnf"
  fi
# 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
  DATADIR=/usr/local/mysql/data
  ledir=/usr/local/mysql/bin
fi

Suggested fix:
As a minimum the test:

  if test -d $MY_PWD/data/mysql ...

needs to be modified to look in the defined data directory, not "./data", however other changes may also be required to make this work in all cases
[28 Apr 2004 16:15] Michael Widenius
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

The problem was that you forgot to set the ledir path (path where mysqld resides) in your my.cnf file.  This is required if you are not using a plain
binary installation.

Here is what I did while testing this:

#Install MySQL
mkdir /local/opt
cd /local/opt
gtar xzf /my/mysql-4.0/mysql-4.0.19-pc-linux-i686.tar.gz
mv mysql-4.0.19-pc-linux-i686 mysql

#Create not default data directory
./scripts/mysql_install_db
mv data /local/opt/test-data

# Define paths
cat > /etc/my.cnf
[client]
socket=/tmp/mysql.sock

[mysqld_safe]
basedir=/local/opt/mysql
datadir=/local/opt/test-data
ledir=/local/opt/mysql/bin
^D

#Start mysqld
./bin/mysqld_safe &
[5 Jun 2004 0:27] C Evans
Your comments are correct. Maybe this was just me being dense, but I must admit
I found the docs unclear in this area.

One reason I suspect is that the variable names "basedir" and "datadir" make
(to me) intuitive sense. By comparison "ledir" doesn't, except possibly as an option for French-speaking users ;-)

It also caught me out that "ledir" is an option for mysqld_safe ONLY, and (unlike most other directives) will cause startup to fail if incorrectly put in the [mysqld] section of my.cnf.

Thanks for looking into this. At least now I know to be careful in this area.
[14 Dec 2005 0:54] Phil Henningsen
I'm having the same problem..  Server: MySQL 5.0.16.  In the previous instructions:
<quote>
#Create not default data directory
./scripts/mysql_install_db
mv data /local/opt/test-data

# Define paths
cat > /etc/my.cnf
[client]
socket=/tmp/mysql.sock

[mysqld_safe]
basedir=/local/opt/mysql
datadir=/local/opt/test-data
ledir=/local/opt/mysql/bin
^D

#Start mysqld
./bin/mysqld_safe &
</quote>

1) I have executed /usr/bin/mysql_install_db --user=mysql

2) What is meant by "mv data /local/opt/test-data"?  Where's "data"?

3) There is no /etc/my.cnf file.  Do I need to create one?  How does MySQL know to look there?  (I previously created a /home/phil/.my.cnf file.  Forgot why.  Should I just delete it?  Or change it?)

Please help ASAP.  I don't understand what's not working.  I'm a newbie!

Thanks,
Phil Henningsen