Changing the mySql data directory.

When having a production install of software it’s always a good idea to seperate the data from the software.

For my TeamCity PI, I’m attempting to do just this.   The software will be running from the MicroSD card.   The data will be stored on an External HDD.

Rather than try to move the folder after setting everything up.  I want to do this straight away.    Here’s how to do it.

 

Firstly let’s get mysql installed.

apt-get install mysql-server

 

next create the root folder for the mysql data to be stored

mkdir /media/hdd/mysql
sudo chown -R mysql:mysql /media/hdd/mysql

 

Next we need to change the datadirectory for mysql

systemctl stop mysql

 

now we can repoint the data dir for example.    Note. your install of mysql could point to a different place, but you should be able to find it by starting at /etc/mysql/my.cnf

sudo nano /etc/mysql/my.cnf

datadir = /media/hdd/mysql

now we can create a new set of starting data.

mysql_install_db --user=mysql --basedir=/usr --datadir=/media/hdd/mysql

finally restart mysql
systemctl start mysql

 

now check that it’s working

systemctl status mysql

And there you go.   A brand new install of mysql with the software on the SD Card and the data on an external HDD.

Leave a Reply

Your email address will not be published. Required fields are marked *