Can not start mysql if the datadir is set to soft link

Sheldon Wang picture Sheldon Wang · Mar 27, 2014 · Viewed 8.9k times · Source

Currently I met a mysql start issue and couldn't figure what happen here. if the datadir set in /var/lib/mysql, and start mysql:

sudo /etc/init.d/mysql start

Starting MySQL...SUCCESS. And the mysql would work fine.

But I need to change the datadir to another partition due to the device space. It would show:

[admin@shwzu lib]$ sudo /etc/init.d/mysql start
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/datadir/shwzu.pid).

I just try every information about it, here is the detail about the settings:

=> 1. if the folder is in /var/lib/mysql, everything is fine:

drwxrwxrwx 6 mysql mysql 4096 Mar 27 06:03 mysql

=> 2. Change the target folder to another partition which name is "test". And create "mysql" folder. Also, I change the owner ans user to mysql. Then create a soft link. (sudo ln -s /test/mysql /var/lib/mysql)

Permission for /test partition: (in /test)

[admin@shwzu /]$ ls -l

drwxrwxrwx   7 root root  4096 Mar 27 06:27 test

Permission for /test/mysql folder:

drwxr-xr-x 6 mysql mysql  4096 Mar 27 06:24 mysql

Permission inside the /test/mysql folder:

drwxr-xr-x 5 mysql mysql 4096 Mar 27 06:24 datadir
drwxr-xr-x 2 mysql mysql 4096 Mar 27 06:24 ibdatadir
drwxr-xr-x 2 mysql mysql 4096 Mar 27 06:24 log
-rwxr-xr-x 1 mysql mysql  158 Mar 27 06:24 RPM_UPGRADE_MARKER
-rw-r----- 1 mysql mysql 2562 Mar 27 06:24 slow_queries.log
drwxr-xr-x 2 mysql mysql 4096 Mar 27 06:24 tmp
-rw-r----- 1 mysql mysql 2031 Mar 27 06:24 shwzu.err

Permission for soft link: (in /var/lib/mysql)

  lrwxrwxrwx 1 mysql mysql   12 Mar 26 10:34 mysql -> /test/mysql

Do init command: sudo mysql_install_db. And it work fine.

  1. Error message:

[admin@shwzu lib]$ sudo /etc/init.d/mysql start Starting MySQL. ERROR! The server quit without updating PID file

(/var/lib/mysql/datadir/shwzu.pid).

And the shwzu.err file which is in /test/mysql/datadir would show:

140327 09:56:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql/datadir
140327 09:56:24 mysqld_safe mysqld from pid file /var/lib/mysql/datadir/shwzu.pid ended

==> So strange! There is no other message here, only two lines!!!!!!

  1. Double check:

    1) There's no mysql process.

    2) Threre's no zombie process.

    3) The owner and user are set to "mysql" for mysql folder and the files which in it.

    4) Clean all the content in datadir. => Failed with the same message.

  2. Try and Error:

    1) Change the name "/var/lib/mysql" folder to "/var/lib/mysql_", and create a soft link(use soft link in the path which is same with the success folder):

    lrwxrwxrwx 1 mysql mysql 12 Mar 26 10:38 mysql -> mysql_

    [Result]: Failed with the same message.
    

    2) Modify the /etc/my.cnf to the target folder "/test/mysql" instead of using soft link:

    [Result]: Failed with the same message.
    

    3) Copy the success folder "/var/lib/mysql" to "/test/mysql" and create a soft link:

    [Result]: Failed with the same message.
    

I really have no idea about the issue, it's confuse me and I didn't find any workaround solution. Is someone who can help me for it?

Many many thanks!

Answer

Manfred picture Manfred · May 23, 2014

Please check your server configuration file. I found "symbolic-links = 0" in my /etc/my.cnf and added a "#" in front of that line:

[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks; to do so, uncomment this line:
#symbolic-links = 0