Changing datadirectory in mariadb

4.5k views Asked by At

Iam trying to change data directory in mariadb, after changing data dir path in the ini file, then try to restart the service, it couldn't start!!! Show a warning like :

> Error 1067: The process terminated unexpectedly

In MySQL, the data dir changing is working perfectly. But I don't know why the same is not working with mariadb.

Only the default path is working...

2

There are 2 answers

0
Vladislav Vaintroub On BEST ANSWER

I should mention wonderful System internals tools (e.g procmon), which would be very helpful not only in this situation but also in many others. Windows error log is a second tool that is really-really helpful, if you'd take a look into it.Know you tools

Now to specific advice for this case - user who runs MariaDB service should be able to create file in the datadir directory. By default, MariaDB uses Network Service, while MySQL is using the Local System (most powerful Windows user).

This change makes MariaDB more secure (less impact if service is hacked), however you should not expect that NetworkService has read-write access to any directory, like LocalSystem has.

So to fix your problem, you either to make the directory writable for NetworkService, or change service user to one that has read-write access to the directory.

0
Vladislav Vaintroub On

Recently someone asked this, and I came up with another answer, involving symbolic links . I feel that this solution might be easiest, no messing up is required in my.ini or service configuration.

How to move data directory after the installation (in case that e.g disk C:\ is getting full).

Unfortunately, this is impossible to do from the MSI, so it needs to be done manually.

You need to

  • Stop the service
  • Move the data directory to new location (preserving permissions)
  • Create symbolic link from old location to new location
  • Give service account (NetworkService) full permissions on symbolic link
  • Start service again

Here is an illustration how to do it from a script (that needs to be run with full admin privileges, e.g on the elevated command line). I use robocopy to copy the files, mklink to create the directory link, icacls for setting permissions on link, and net to start/stop service

set SERVICE=MySQL
set SRCDIR="C:\Program Files\MariaDB 10.1\data"
set DESTDIR="D:\data"

net stop %SERVICE%
robocopy %SRCDIR% %DESTDIR% /MIR /SEC /MOVE
mklink /d %SRCDIR% %DESTDIR%
icacls %SRCDIR% /grant "NT AUTHORITY\NetworkService":F
net start %SERVICE%

Currently, this would not remove the new datadir on uninstall, even if you chose "Remove data" in MSI.