Wednesday, 25 July 2018

MySQL: Move Data Directory to a New Location on Ubuntu 16.04

In this post, I am sharing required steps to move MySQL Data Directory from old location to new location.
Check the current data directory of MySQL:
Stop the MySQL Service:
Confirm the inactive status of MySQL Service:
Output:
Use rsync with -av flag to copy the existing database directory to the new location:
Rename old MySQL Data Directory:
Change (datadir=) parameter in MySQL Config file (mysqld.cnf) for pointing to the New Data Location:
My Sample mysqld.cnf:
Now, Check below sample error:
To avoid above error, configure AppArmor Access Control Rules:
AppArmor: AppArmor (“Application”) is a Linux kernel security module that allows the system administrator to restrict programs’ capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths.
Open AppArmor for edit:
Add new entry of new data location path:
Please check below sample output of my AppArmor:
Because don’t add # in new entry and also make sure that old path is there with #.
After change, restart the AppArmor:
Create the minimal directory structure:
Now, Start the MySQL Service:
Check the status of MySQL Service:
Now, connect MySQL and check the new datadir location:

0 comments:

Post a Comment