i setup a RAID 5 system for our mysql database and wanted to move it over on ubuntu 10.


first stop mysql
service mysql stop

i’m paranoid, so i check the status
service mysql status

copy your MySQL database files to the new location. in this instance my RAID drive is located at:

let’s move database:
mv /var/lib/mysql /media/speedy/mysql

change ownership/group to mysql:
sudo chown mysql:mysql /media/speedy/mysql

i make a backup of the existing database name mysql-bu (move it):
mv /var/lib/mysql /var/lib/mysql-bu

make a new symbolic link and check perms:
sudo ln -s /mnt/mysql /var/lib/mysql

CHANGE MySQL config file, my.cnf to reflect new data directory(datadir):
datadir         = /media/speedy/mysql


o.k., after you’ve done all of this, apparmor will try and get in your way if you use these new settings.

Edit apparmors mysql config file


replace the original MySQL paths with your new MySQL location:

/media/speedy/mysql/ r,
/media/speedy/mysql/** rwk,

***WARNING*** if you make a back up of the usr.sbin.mysqld don’t put it in the apparmor.d directory! Otherwise, when you try to restart apparmor, it will load both configuration files. This had me stumped for hours………..

Now, MySQL should be ready to run in your new location.

PHPMyAdmin needs to be reconfigured:

dpkg-reconfigure phpmyadmin

I wanted to move mysqld.sock to the RAID drive to help with performance.

Reconfigure PHP to use the new socket: