MariaDB Data Directory Migration: Checks Before and After the Move
To move the MariaDB data directory, pause application writes, shut the server down cleanly, copy the whole data directory, and change the datadir setting the service actually uses. Reopen writes after confirming the new path and the existing data. The checks below apply to one standalone instance on the same host and MariaDB version.
Identify the instance and record a baseline
Pause application writes and scheduled jobs, then run this SQL before changing anything. Replace migration_demo.orders and id with a table and key you will verify after the move. For a large table, counting every row may be expensive. You can record a few representative record keys and expected values ahead of the maintenance window.
SELECT VERSION() AS server_version,
@@hostname AS server_host,
@@port AS server_port,
@@GLOBAL.datadir AS data_directory;
SELECT COUNT(*) AS row_count, MAX(id) AS highest_id
FROM migration_demo.orders;
If the count is 2 and the highest ID is 42, the same query should return those values immediately after the move. Record the hostname and port together with the address or socket your app uses to help identify the instance. This is a quick comparison. Check representative records and read access with the application account as well.
Check the effective configuration and target volume
In an elevated Windows PowerShell session, replace MariaDB with the actual service name. If PathName shows a --defaults-file argument, inspect that file. Check that the Windows account in StartName can read and modify files in the new folder. It may differ from the SQL login.
Get-CimInstance -ClassName Win32_Service -Filter "Name='MariaDB'" |
Select-Object Name, State, StartName, PathName
On a systemd-based Linux installation, use the actual unit name. ExecStart shows the start command, and FragmentPath and DropInPaths show the unit and its overrides. If User is empty, also check the server settings to identify the runtime account. Point findmnt at the existing destination folder. If you expect a separate volume, check that the expected device is mounted and will be ready before the service starts on reboot.
systemctl show mariadb -p FragmentPath -p DropInPaths -p ExecStart -p User
findmnt --target /data/mariadb
Decide when to copy and switch paths
Keep a copy of the effective server configuration and a separate, recoverable data backup. Confirm free space. Plan separately for paths outside the data directory, such as external tablespaces, logs, or encryption keys. On Linux, verify traversal permissions on parent directories and the relevant AppArmor or SELinux policy.
MariaDB backup and restore methods
- Wait for the database process to exit cleanly. Copy the contents of the entire data directory to an empty destination and check the copy result. Leave the old files in place.
- Set
datadirto the new absolute path in a server option group the service reads. If your setup also requires moving the option file, verify that the service will read it at the new location. - Start the service and review errors. Keep app writes paused and connect through the same endpoint to verify
@@GLOBAL.datadirand the baseline data.
This is an example server option. On Windows, you can use forward slashes in the actual path, such as D:/Database/MariaDB/data.
[mysqld]
datadir=/data/mariadb
Commands and configuration for moving MariaDB on Ubuntu and Windows
Verify existing data before reopening writes
Verify the path, representative data, and reads with the application account. A healthy service status alone cannot confirm these. If you need a write check, use an approved probe in a separate test database before opening production writes. Keep writes paused if any validation fails.
Choose a rollback based on whether writes resumed
If the old path appears, check that you reached the right instance and that another option file or service argument did not override the setting. If startup fails, begin with the file and path mentioned in the first error. Use the service journal on Linux and the MariaDB error log and Event Viewer on Windows. If databases are missing, check whether the copy created an extra parent folder at the destination.
sudo journalctl -u mariadb -n 50 --no-pager
Diagnose MariaDB startup failures
- Before production writes resume, shut down cleanly, restore the original settings and path, and repeat the baseline check.
- After production writes resume, the old copy may be stale. Pause writes again, back up the current data, and plan recovery or a move back that includes those writes. Keep the two directories’ files separate.




