СHRISTMAS
WHEEL OF FORTUNE

Tap the button and win a guaranteed prize right now!

By registering, you are signing up to receiving e-mails.
VB
February 20 2023
Updated December 6 2024

How to change the MariaDB data directory to a new location in CentOS 7

CentOS Databases

What is MariaDB

MariaDB is very popular SQL-based dadabase system. It is more powerful and fully compatible with it's "ancestor" - MySQL.

Why might you need to move MariaDB data directory to another location

There are two mainly reasons:

  • Current disk's space is over;
  • Faster disk drive installed and you want to improove databases performance.

How to change database data location

Before any opeations I strongly advice you to ensure what is current data location. Just open an SSH-session as root user, login to the MariaDB and run this command:

mysql -u root

select @@datadir;

pic1

Quit and stop the service:

quit;

service mariadb stop

pic2

Create new directory and move databases data into:

mkdir <path_to_directory> && rsync -av <current_data_directory> <new_data_directory>

pic3

Edit database service configuration file:

sed -i 's|<current_data_directory>|<new_data_directory>|g' /etc/my.cnf

cat <<EOT >> /etc/my.cnf
[client]
socket=<new_data_directory>/mysql.sock
EOT

pic4

Create special socket-file and set permissions:

touch <new_data_directory>/mysql.sock && chmod 777 <new_data_directory>/mysql.sock

pic5

Start the service:

service mariadb start

pic5

 

Check where is data located now:

mysql -u root

select @@datadir;

pic8

Conclusion

After this article reading you knew what is MariaDB, possible reasons to move its data to other location and how to do this.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 4
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
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.