Changing the default MySQL data directory
By Hilmar MeijerOn march 12, 2015
About commandline, database

Move your files to the desired directory. Most of the time MySQL database files are located in:
/var/lib/mysql/You can move them as followed:
mv /var/lib/mysql/* /yourdirectory/You now have to edit your mysql configuration. The my.cnf file is most of the time located in:
/etc/ or /etc/mysql/Find the section [mysqld] then add or edit the following lines:
datadir=/yourdirectory/Thats it. Now you can start your MySQL server again.
socket=/yourdirectory/mysql.sock