Hello, there will be times when you need to change the Mysql or MariaDB container directory because your hard drive is full or some other reason.
However, systems like Ubuntu and Debian often use AppArmor to control the application’s access to system resources. And modifying it is potentially risky, so this article provides another solution.
1. Stop the MySQL or MariaDB service.
sudo systemctl stop mysql
2. Create a new data directory.
sudo mkdir /new-data-directory
3. Set ownership and permissions for the new directory.
sudo chown -R mysql:mysql /new-data-directory
sudo chmod 750 /new-data-directory
4. Copy data to new folder
sudo cp -R /var/lib/mysql/* /new-data-directory/
5. Mount the new directory to the Mysql or MariaDB directory
mount --bind /new-data-directory /var/lib/mysql
6. Start The MySQL or MariaDB service.
sudo systemctl start mysql