How to move the MariaDB data directory

How to move the MariaDB data directory

Hello colleagues.

In today's article, I will tell you how to change the home directory in MariaDB. The reasons for changing directories may be different, but the most basic is when you connect a disk and want to transfer the database to it. In MariaDB, you can change the home directory both after installing the database and before installing the DBMS, but today I will show you how to change the directory after installing the DBMS.

This article is suitable for the database administrator as well as for programmers and engineers.

 

The content of the article:

  1. Check where the home directory is now.
  2. Directory change.

 

1. Check where the home directory is now.

By default, the MariaDB home directory is located in the /var/lib/mysql directory. Let's make sure of this, for this we will use the command in the console:

mysql> SHOW VARIABLES LIKE 'datadir';

As you can see from the picture, now the home directory is located in /var/lib/mysql


 

2. Directory change.

Be sure to stop the database before doing this.

$. sudo service mariadb stop

Let's create a new directory where we want to transfer all the database data.

$. sudo mkdir -p /app/mariadb/data

And now you definitely need to make the owner of the /app/mariadb/data directory of the user and the mysql group.

$. sudo chown -R mysql:mysql /app/mariadb/data

Now let's transfer everything from the /var/lib/mysql directory to /app/mariadb/data, for this we will use the command:

$. sudo cp -r /var/lib/mysql/* /app/mariadb/data

The next step is now to explicitly specify in the configuration file where the new directory for MariaDB will be. This file is located in the /etc/my.cnf.d/server.cnf directory

$. sudo vim /etc/my.cnf.d/server.cnf

And add the datadir parameter to it with the value of the new directory.

Save and close and start the database.

$. sudo service mariadb start

 

Now let's check everything back. In the console we write:

mysql> SHOW VARIABLES LIKE 'datadir';

And now we see that the new directory has been successfully applied.

 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES

MariaDB - ERROR Incorrect definition of table
MariaDB - ERROR Incorrect definition of table
MARIADB
Read more
Mariabackup backup - gzip compression
Mariabackup backup - gzip compression
MARIADB
Read more
Mariabackup error - Error writing file UNKNOWN errno 32 Broken pipe
Mariabackup error - Error writing file UNKNOWN errno 32 Broken pipe
MARIADB
Read more