Menu icon
RedCrackle
Menu icon
Services
01Design Transformation
About UsCase StudiesBlogContact Us

<

Blog post

How to change location where MySQL stores data on disk

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:

  1. Stop MySQL server.

sudo service mysql stop
  1. Create the new /data directory.

sudo mkdir /data
  1. Move the existing MySQL directory to /data.

sudo mv /var/lib/mysql /data/
  1. Open /etc/mysql/my.cnf file and change the value of datadir ftom /var/lib/mysql to /data/mysql.

  2. 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,
  1. Restart AppArmor.

sudo service apparmor restart
  1. Restart MySQL

sudo service mysql restart

Now MySQL should use the new directory /data/mysql to store all of its data.

Neerav Mehta

Neerav Mehta

Founder & CEO

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.

View all posts

>

Read Next

10 Tips For Entrepreneurs In 2015

10 Tips For Entrepreneurs In 2015

Learn more

10 Ways To Increase Productivity At Work

10 Ways To Increase Productivity At Work

Learn more

30 best WordPress widgets for your site

30 best WordPress widgets for your site

Learn more

Let’s get you started!

Contact Us

>

RedCrackle

Explore

About Us

Services

Contact Us

Our address

5346 Gerine Blossom Dr,

San Jose, CA 95123

USA

Socials

Twitter
LinkedIn

© 2023 RedCrackle. All rights reserved.