Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  hmayag May 14 '13 at 20:47
    
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. –  Jester87 May 14 '13 at 21:01
    
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 –  hmayag May 14 '13 at 21:37
    
I tried running mysql_install_db but it didn't seem to do anything. I keep getting permission errors. –  Jester87 May 14 '13 at 23:40
    
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? –  Jester87 May 14 '13 at 23:50

1 Answer 1

up vote 0 down vote accepted

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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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