List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:May 12 1999 3:52pm
Subject:mysql symlink change
View as plain text  
>>>>> "David" == David R Saunders <david@stripped> writes:

David> MySQL Folks,
David>   I have been looking at how I can distribute mysql databases across
David> multiple filesystems.  Several earlier postings suggested the use of
David> symlinks, which I think are the way to go.  I plan to create a cron job
David> which will select a database, lock all of it's tables, physically move the
David> database to another filesystem, create a symlink to it, and unlock the 
David> tables.
David>   One problem with a symlinked database is that a
David> the DROP DATABASE command fails--all the tables of a symlinked
David> database are deleted, but the code expecting a directory and not
David> a symlink to a directory.
David>   I obtained the mysql-3.22.22 source and created the change to
David> sql/sql_db.cc provided below.  I've been able to test this change
David> and it appears to work under RedHat 5.2.
David>   My questions are:

David> 	Is this the only change necessary to support symlinks?

Probably not, but this should be ok for now.

(One should sometimes in the future be able to give an argument to
CREATE TABLE to let this create the symbolic link, but for the moment
this isn't that important)

David> 	Is there some other reason why symlinks shouldn't be used?

No.

David> 	Assuming there aren't any other problems, could this be
David> 	made a permanent part of mysql?

I just added the following (very similar code) to the MySQL 3.23
source tree:

    /*
      If the directory is a symbolic link, remove the link first, then
      remove the directory the symbolic link pointed at
    */
    char path2[FN_REFLEN];
    int linkcount = readlink(path,path2,sizeof(path2)-1);
    if (linkcount > 0)			// If the path was a symbolic link
    {
      *(path2 + linkcount) = '\0';
      if (my_delete(path,MYF(MY_WME)))
      {
	send_error(&thd->net);
	goto exit;
      }
      strmov(path,path2);
    }
    if (rmdir(path) < 0)    /* original line 149 of sql/sql_db.cc  */
      net_printf(&thd->net,ER_DB_DROP_RMDIR, path,errno);
    else
      send_ok(&thd->net,deleted);
  }

Regards,
Monty
Thread
mysql symlink changeDavid R. Saunders12 May
  • mysql symlink changeMichael Widenius13 May