Mysql Datadir on different hard drive
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.
- First head to the MySQL data directory and move all
ibdata
files and allib_logfile
files to a temp folder (should look similar tomv /path_to_mysql_data_directory/ib* /path_to_temp_folder/
). - Run
sudo service mysqld start
and it should start. - Run
sudo service mysqld stop
and it should stop. - 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/
). - Run
sudo service mysqld start
again and everything should start.
This solution did work for me, but I haven't tested it elsewhere.
Related videos on Youtube
Jester87
Updated on September 18, 2022Comments
-
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 almost 11 yearsFirst 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 almost 11 yearsI 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 almost 11 yearsYes, 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 almost 11 yearsI tried running
mysql_install_db
but it didn't seem to do anything. I keep getting permission errors. -
Jester87 almost 11 yearsWell, 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 over 10 yearsI had similar problem and here's solution: askubuntu.com/questions/284850/…
-