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
  if test -z "$defaults" -a -r "$DATADIR/my.cnf"
# Next try where the source installs put it
elif test -d $MY_BASEDIR_VERSION/var/mysql
# Or just give up and use our compiled-in default

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.

  • This worked. But why doesn't it allow to change the configs? – user4035 Feb 25 '16 at 15:20
  • What sets $MY_BASEDIR_VERSION? Beyond that, none of the tests would allow for this syntax: /mnt/C/mysql. – Rick James Mar 3 '16 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.