Mysql Datadir on different hard drive

6,770

I faced the exact same problem, but I've found a better alternative that did work for me, since changing the user to root in the my.cnf file didn't work for me.

  1. First head to the MySQL data directory and move all ibdata files and all ib_logfile files to a temp folder (should look similar to mv /path_to_mysql_data_directory/ib* /path_to_temp_folder/).
  2. Run sudo service mysqld start and it should start.
  3. Run sudo service mysqld stop and it should stop.
  4. Take the file you moved to the temp folder and put them back in the MySQL data directory (should look similar to mv /path_to_temp_folder/ib* /path_to_mysql_data_directory/).
  5. Run sudo service mysqld start again and everything should start.

This solution did work for me, but I haven't tested it elsewhere.

Share:
6,770

Related videos on Youtube

Jester87
Author by

Jester87

Updated on September 18, 2022

Comments

  • Jester87
    Jester87 over 1 year

    I'm currently running Ubuntu 13.04 and MySQL 5.5. I have been using InnoDB, and the default location for installation. The problem is that my main OS partition is fairly small (36GB), and I need to move my database to my 2TB drive.

    I'm trying to change MySQL datadir from:

    /var/lib/mysql
    

    to:

    /path/to/new/directory
    

    but I've been running into all kinds of problems. MySQL refuses to start, and generally tells me there are problems with permissions. This doesn't make any sense to me, though. Here is what I have tried doing:

    I copied the files:

    cp -R /var/lib/mysql /path/to/new/directory
    

    I edited /etc/mysql/my.cnf :

    datadir=/path/to/new/directory
    

    Updated the permissions:

    chown -R mysql:mysql /path/to/new/directory
    

    Updated Apparmor:

    /path/to/new/directory/ r,
    /path/to/new/directory/** rwk,
    

    I make sure to reset Apparmor:

    service apparmor restart
    

    But it still gives me errors. I am not sure what else I need to do. Does anyone have a definitive guide to making this work under Ubuntu 13.04, MySQL 5.5, and InnoDB?

    • hmayag
      hmayag almost 11 years
      First of all, this is not a Ubuntu issue. Second, in general you cannot just copy a couple of folders and demand that the software continues to function as nothing has changed. Third, start by reading the MySQL reference manual. The chapter about installation is exaustive. Fourth, why move the program? Just move the datadir... and anyway standard mysql database size limit is 2GB unless set otherwise at initialization.
    • Jester87
      Jester87 almost 11 years
      I thought this might be an Ubuntu issue because of Apparmor. I didn't just copy a few folders. I never said I was moving the whole program.
    • hmayag
      hmayag almost 11 years
      Yes, I read your question more carefully. Sorry about that. Try initializing a new data space from the command line. I don't remember the exact mysql script that does that. Edit: found it. dev.mysql.com/doc/refman/5.0/en/mysql-install-db.html
    • Jester87
      Jester87 almost 11 years
      I tried running mysql_install_db but it didn't seem to do anything. I keep getting permission errors.
    • Jester87
      Jester87 almost 11 years
      Well, I got it to work if i change the user to root in my.cnf. This is not ideal, though. Any suggestions on figuring out where the permission problems are happening?
    • kshishkin
      kshishkin over 10 years
      I had similar problem and here's solution: askubuntu.com/questions/284850/…