What is MariaDB
An offshoot of MySQL, retaining backward compatibility and featuring the integration of additional storage engines and advanced features. Mariadb comes instead of MySQL in many Linux distributions (Fedora; SUSE 12; RHELL 7; Arch Linux, Debian 9). This was done in order not to depend on Oracle distribution, because of the possibility to limit them for other distributions. MariaDB is also implemented in big projects such as Wikipedia, Google Cloud, SQL, and Nimbuzz.
In this publication, I will change the MariaDB data directory on the Linux CentOS 7 operating system.
Changing the directory requires
- MariaDB preinstalled and configured
- User with root access to the database
If you don't have MariaDB installed, or a special user with full rights has not been created, you can refer to our instructions on how to install MariaDB on a Linux CentOS operating system.
Directory change process
Let's check if the database service is up and running.
Connect to the MariaDB database.
The most important thing before changing the directory, determine where you want to move the database. To do this, check which databases exist.
Check the path of the database at the moment.
Exit the database, and go to the application directory.
Review and verify that your databases exist in this folder.
The MariaDb database application must be disabled before changing the path.
You can check if the application is running using this command.
Define a new directory where you want to place your databases.
In my example I will use the local directory path.
Copy the Mysql directory to the "new-sql" folder we have created.
Edit the MariaDB config.
Change the datadir and socket lines, also add the client setting.
After configuring the configuration file, don't forget to save it, change the properties of the configuration.
chown mysql:mysql /new-sql/mysql
Turn on the database service, and check the changes you have made.
Conclusion
In this publication, I've discussed how to change the directory of MariaDB databases on the Linux CentOs 7 operating system.
In fact, changing the directory is not a difficult task, it is necessary not to forget these important points :
- Create a new directory for the database.
- Shut down the MariaDB service.
- Copy the old database directory to the new directory.
- Change the configuration file
- Change the file properties
- Start the service and check the local database path