Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Hi All, I'm brand new to MySQL/PHP/Apache and so far so good. I got all three working together, my PHP recognises calls to my MySQL database. Here's my question: By ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Posts
    33

    Moving MySQL datafile to another location


    Hi All,

    I'm brand new to MySQL/PHP/Apache and so far so good. I got all three working together, my PHP recognises calls to my MySQL database.

    Here's my question:

    By default all database files are located at: /var/lib/mysql/"db_name". I really need the datafile on another disk partition /data/my_data/"db_name".

    To do this, I stopped MySQL, copied (cp) all datafiles from /var/lib/mysql to /data/my_data/, then
    modified the /etc/my.cnf file arguement from datadir=/var/lib/mysql to datadir=/data/my_data.

    Then attempted a restart of MySQL. It fails with this error:
    Code:
    "Initializing MySQL database: Installing all prepared tables
    060125 10:41:44 [Warning] Can't create test file /data/my_data/mysql/localhost.lower-test
    /usr/libexec/mysqld: Can't change dir to '/data/my_data/mysql/' (Errcode: 13)
    060125 10:41:44 [ERROR] Aborting
    "
    I just changed back to the original and the base came right up.

    What I'm I doing wrong? Do I need to include 'mysql' in my path?

    Regards
    Mike in Toronto

  2. #2
    Just Joined!
    Join Date
    Jan 2006
    Posts
    77
    i would look at the permissions set to /data/my_data. if you start mysqld under its own user it might not have sufficient rights to read that dir. if permissions aren't the issue i'd guess a google search for "mysqld errcode 13" might help.

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Errno 13 is permission denied. I'd have copied the files (as root) with:
    Code:
    cd /var/lib/mysql
    find . -print -depth | cpio -pvdum /data/my_data
    which should preserve uid, gid and permissions.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Mar 2005
    Posts
    33
    It appears it's some kind of permission problem alright. I installed MySQL directly from 'up2date' (Red Hat) command line as root. A user "mysql" was created by the install and all the database file are stored with 'mysql' as the owner.

    I tried chmod/chgrp to mysql from root after I created the directories, but that didn't appear to fix the problem.

    I'm really new at Unix based O/S's and obviously don't completely understand how to correctly setup an environment. I simply cannot believe that copying files from one directory to another and having the application recognise the change can be this difficult. This problem must be because I do not understand the conditions required to correctly administer an application on Linux.

  6. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by CanMike
    It appears it's some kind of permission problem alright. I installed MySQL directly from 'up2date' (Red Hat) command line as root. A user "mysql" was created by the install and all the database file are stored with 'mysql' as the owner.

    I tried chmod/chgrp to mysql from root after I created the directories, but that didn't appear to fix the problem.

    I'm really new at Unix based O/S's and obviously don't completely understand how to correctly setup an environment. I simply cannot believe that copying files from one directory to another and having the application recognise the change can be this difficult. This problem must be because I do not understand the conditions required to correctly administer an application on Linux.
    I suspect the problem lies in how you copied the files. If you try using the find/cpio combination as rthe root user, your files should have their attributes preserved and MySQL should be able to access them. I believe that MySQL requires that the data files are only writable by the mysql user (not the group or other), so you chould have specifed 0600 to chmod the files and 700 on the my_data directory.

  7. #6
    Just Joined!
    Join Date
    May 2005
    Location
    Southern California, US
    Posts
    5
    I was wondering if you made any progress on this issue as I am having the same problem. In my case the default datadir is
    /var/lib/mysql

    But I'd like to make it:
    /home2/www/db

    These dirs have identical permissions. After editing my.cnf to point to the new datadir, the daemon will not start. Log shows Error Code: 13, permission denied, but I do not see how this is possible from a basic permissions point of view.

    My only guesses remaining are, there is some error or problem in the startup script, "/etc/rc.d/init.d/mysqld" or it is related to SELinux security contexts.

    System is FC4 on an AMD64, otherwise running nicely so far.


    Any help, much appreciated.

  8. #7
    Just Joined!
    Join Date
    Mar 2006
    Posts
    1

    I Have Problems with new data Path

    I have the same problem.
    I have mounted a new drive at /var/lib/mysql mount point and mysql will not start

    I did copy the original files from /var/lib/mysql to the new drive before mounting
    so it would have the same files.....and it failed to start.

    This is really frustrating because everthing looks correct !
    When I umount /var/lib/mysql, then it will works normally.

    060304 13:03:37 mysqld started
    060304 13:03:37 [Warning] Can't create test file /var/lib/mysql/localhost.lower-test
    /usr/libexec/mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)
    060304 13:03:37 [ERROR] Aborting

    060304 13:03:37 [Note] /usr/libexec/mysqld: Shutdown complete

    060304 13:03:37 mysqld ended

  9. #8
    Just Joined!
    Join Date
    Dec 2005
    Posts
    13
    have u tried giving mysql ownership to your new data location??
    e.g. chown -R mysql.mysql /path/to/mysql

  10. #9
    Just Joined!
    Join Date
    Nov 2006
    Posts
    1

    It isn't permissions

    I've been playing with this problem for a few hours, and it certainly isn't permissions.

    I've checked entire paths, and it's fine. I know blaming permissions is an easy-out, but... nope!

    I'm doing this on Cent4.4, quad pIII, with the following packages/versions:
    mysqlclient14-4.1.14-4.2.c4.1
    mysql-5.0.22-1.centos.1
    mysqlclient10-3.23.58-9.2.c4
    mysql-server-5.0.22-1.centos.1

    As with everyone else, I'm a bit lost, so if anyone has some ideas they would be appreciated.

  11. #10
    Just Joined!
    Join Date
    Nov 2006
    Posts
    1

    Pretty sure it's SELinux

    If you have ever tried to move the root of an apache web server you'll have seen something like this before - I'm pretty sure it's SELinux, which is normally on by default.

    If you start 'system-config-securitylevel' (RHEL/CentOS) in a graphical environment and click on th SELinux tab, then right down at the bottom of the 'Modify SELinux Policy' section there is a menu item 'SELinux Service Protection'. Expand this and one of the items is 'Disable SELinux protection for mysqld daemon'. Check the box next to this and click 'OK'. /etc/init.d/mysqld should now start (well, unless there's other errors in /etc/my.cnf of course!)

    HYH, Chris.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •