<
Neerav Mehta
Founder & CEO
If you install MySQL via apt-get on Ubuntu, it comes with pre-defined setting. One of these settings is datadir, which specific where MySQL stores all its data on disk. By default, it is set to /var/lib/mysql. Sometimes we need to change this location. As an example, we want to store MySQL data in /data/mysql. Here are the steps to accomplish that:
sudo service mysql stop
sudo mkdir /data
sudo mv /var/lib/mysql /data/
Open /etc/mysql/my.cnf file and change the value of datadir ftom /var/lib/mysql to /data/mysql.
If you have AppArmor installed, then there are two more steps. AppArmor is a Mandatory Access Control (MAC) utility to confine programs to a limited set of resources. So even if you change MySQL to use /data/mysql directory, AppArmor will not allow MySQL to use it. We need to change AppArmor settings. Open /etc/apparmor.d/usr.sbin.mysqld and remove the following lines:
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
Add the following lines instead.
/data/mysql/ r,
/data/mysql/** rwk,
sudo service apparmor restart
sudo service mysql restart
Now MySQL should use the new directory /data/mysql to store all of its data.
Neerav Mehta
Neerav Mehta is the Founder & CEO of Red Crackle. With sterling qualities, Neerav’s technological acumen is firing a generation of progressive companies on the digital path. With an undergraduate degree in Electrical Engineering from India's most prestigious institution IIT Bombay and having spent seven years developing and contributing to the launch of AMD's innovative line of computer products, Neerav founded Red Crackle where he is lauded for his dynamic and innovative genius.
Let’s get you started!