Linux Slackware MySQL can't move datadir By default datadir was located in /usr/lib/mysql. I decided to move it to a different disk partition: /mnt/C/mysql:

drwxr-x--- 25 mysql mysql 36864 Feb 25 12:52 mysql


I opened /etc/my.cnf, but there was no datadir command there. So, I added one inside [mysqld] block:

datadir     = /mnt/C/mysql


But when I try to start mysqld, it seems to be using the old directory:

bash-4.2# /etc/rc.d/rc.mysqld start
mysqld_safe Logging to '/var/lib/mysql/asus.err'.
touch: cannot touch ‘/var/lib/mysql/asus.err’: No such file or directory
chown: cannot access ‘/var/lib/mysql/asus.err’: No such file or directory
mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/bin/mysqld_safe: line 107: /var/lib/mysql/asus.err: No such file or directory
/usr/bin/mysqld_safe: line 144: /var/lib/mysql/asus.err: No such file or directory
mysqld_safe mysqld from pid file /var/run/mysql/mysql.pid ended
/usr/bin/mysqld_safe: line 107: /var/lib/mysql/asus.err: No such file or directory


I found the portion of /usr/bin/mysqld_safe file, responsible for the error:

# Try where the binary installs put it
if test -d $MY_BASEDIR_VERSION/data/mysql
then
  DATADIR=$MY_BASEDIR_VERSION/data
  if test -z "$defaults" -a -r "$DATADIR/my.cnf"
  then
    defaults="--defaults-extra-file=$DATADIR/my.cnf"
  fi
# Next try where the source installs put it
elif test -d $MY_BASEDIR_VERSION/var/mysql
then
  DATADIR=$MY_BASEDIR_VERSION/var
# Or just give up and use our compiled-in default
else
  DATADIR=/var/lib/mysql
fi


So, it seems to be using the default dir: /var/lib/mysql. I changed it to /mnt/C/mysql, but it didn't help.

What am I doing wrong?
The easiest way is to create a symbolic link to new data directory.
When your new data directory is ready to use, stop mysql server and type:

rm -r /var/lib/mysql
ln -s /mnt/C/mysql /var/lib/mysql


Now you can restart mysql server with standard datadir.