07.06.2023

How to change catalog of database MariaDB on Linux CentOS 7

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

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.

systemctl status mariadb

Connect to the MariaDB database.

mysql -u *your user* -p

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.

select @@datadir;

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.

systemctl status mariadb

Define a new directory where you want to place your databases.

In my example I will use the local directory path.

mkdir new-sql

Copy the Mysql directory to the "new-sql" folder we have created.

Edit the MariaDB config.

nano /etc/my.cnf

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 /etc/my.cnf
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 :