Serverspace Black Friday
BM
November 11, 2022
Updated November 11, 2022

How to change catalog of database MariaDB on Linux CentOS 7

CentOS Linux

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.

systemctl status mariadb

1.1maricos

Connect to the MariaDB database.

mysql -u *your user* -p

1maricos

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;

2maricos

Exit the database, and go to the application directory.

3maricos

Review and verify that your databases exist in this folder.

4maricos

The MariaDb database application must be disabled before changing the path.

5maricos

You can check if the application is running using this command.

systemctl status mariadb

6maricos

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

7maricos

In my example I will use the local directory path.

mkdir new-sql

8maricos

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

9maricos

Edit the MariaDB config.

nano /etc/my.cnf

10maricos

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.

11maricos

chown mysql:mysql /etc/my.cnf
chown mysql:mysql /new-sql/mysql

Turn on the database service, and check the changes you have made.

12maricos

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

 

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.