This guide will show you how to move the mysql directory to another partition or secondary drive and then symlink the new location to /var/lib/mysql. This has the benefit of not requiring any modification of the /etc/my.cnf file.
This is best practice whenever altering anything with mysql as far as I am concerned:
mysqldump --all-databases | gzip > /home2/alldatabases.sql.gz
After the mysqldump completes go ahead and stop mysql and confirm that it has no lingering processes before proceeding:
/etc/init.d/mysql stop
ps faux|grep mysql
Now we will make our new mysql directory. In my example I am moving this to /home2 so be sure to adjust the commands to match your needs:
mkdir /home2/var_mysql
Now that we have our new directory we will move the mysqls, reset ownership on the new location and create our symlink:
mv /var/lib/mysql /home2/var_mysql
chown -R mysql:mysql /home2/var_mysql
ln -s /home2/var_mysql/mysql /var/lib/mysql
/etc/init.d/mysql start
To test that everything went smoothly lets log in to mysql:
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.42-cll MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
This is why we created the full database dump first. To restore it we would run the following:
gunzip < /home2/alldatabases.sql.gz | mysql