A client asked me if I can help their WordPress developer configure a development Linux box. They created a separate partition and wanted to change their MariaDB Data Directory Location on their CentOS server.

After taking a walk in New York City by the Madison Square Park I decided to put this tutorial together. There are some simple steps:

  1. Moving MariaDB Data Directory
  2. Pointing to the New Data Location
  3. Restart MariaDB

Moving MariaDB Data Directory

We need to verify the the current MariaDB data location first. Login using the below command. Enter your password when prompted:

mysql -u root -p

Then, once logged in run the following:

select @@datadir;

You should see the current location:

Change MariaDB Data Directory
MariaDB data location

Type exit.

Next, stop MariaDB:

sudo systemctl stop mariadb

Confirm it really stopped:

sudo systemctl status mariadb

Read the output and make sure it says:

Stopped MariaDB database server.

Point to the New Data Location

Now, we need to tell MariaDB where the new location will live. Edit /etc/my.cnf by running:

sudo vim /etc/my.cnf

Find the line that begins with ‘datadir=’ and make the changes to the new location. Also, change the ‘socket=’ if necessary.

Remember, you can also define a custom .cnf in side the /etc/my.cnf.d/ 

Write your above changes and now let go start MariaDB and see.

Finally, start MariaDB by running this command:

sudo systemctl start mariadb

Verify its running:

sudo systemctl status mariadb

Also, repeat the first command above:

mysql -u root -p
select @@datadir;

In order to verify the changes. Type exit or \q.

Cheers! Remember to see my T-shirt and coffee mugs shop. I designed some inspirational ones. Let me know what you think.

Hope you enjoy this Change MariaDB Data Directory brief tutorial.

Leave a comment

Your email address will not be published.