We need to change the default data directory /var/lib/mysql to a different location. Now we will see how to change the default MySQL / MariaDB data directory to a different path on a CentOS/RHEL 7 server.
The new directory in /data/techrunnr/mysql-data and this directory should have ownership of mysql:mysql
1. Find the current default data directory using the following command.
Now we can see default directory is /var/lib/mysql/
2. Copy MySQL data to a new location
First, we need to stop the MariaDB service
Now Database is stopped, now we will copy the data to a new location through rsync.
Once rsync is complete, rename the folder.
3.Configure New Mysql Data Directory
Will edit my.cnf file to reflect the new directory changes.
check for [mysqld] and [client] to make the changes.
Then save the changes.
Change the SELinux Context to Data Directory
Now need to add new /data/techrunnr/mysql-data before starting Maria DB.
Now start the mariadb service
Now we will check the changes are working or not.
Once all are verified and existing data is available, we can remove the backup data directory by rm -Rf /var/lib/mysql.bak
© 2019, Techrunnr. All rights reserved.