How to store mysql data in different drive

Feb 14 2016

Some time we require to store mysql data in different drive or folder instead of default on.

To change the data storage location of mysql we need to following changes.

Step1:- Stop Mysql service. you can use /etc/init.d/mysql stop.

Step2:-Create a new folder where you want to store the data. eg new_data_folder.

Step3:- Change the user and group of this folder. chown -R mysql:mysql new_data_folder

Step4:- Copy existing data in new folder from default location(/var/lib/mysql/)

Update the data location in my.cnf file


/data/ r,
/data/** rwk,
…and then reload the AppArmor profiles:

# service apparmor reload