• Filip Holub

Change default folder for data and log in SQL Server on Linux

When we have installation of SQL Server on Linux done, location for data and log files is here /var/opt/mssql/data, by default. In this demo, I will show you how to change this location by filelocation.defaultdatadir and filelocation.defaultlogdir. It is usefull for each distribution of Linux, such as Ubutnu, RHEL or SUSE. Let's get start!


"First of all, you have to connect as root user on your Linux machine!"

  • Now, we can check default folder for data and log files via Management studio:

Default locations for Data and Log folders

The next step is that I will create a new dedicated folder for data and for transaction logs, by following commands:

  • pwd - Return the name of working directory

  • cd /var/opt/mssql/data - Means "Change Directory", change current working directory.

  • sudo mkdir datafiles - mkdir means "make directory", which is command for create new directory, that's all. We created datafiles for our data.

  • sudo mkdir logfiles - mkdir means "make directory", which is command for create new directory, that's all. We created logfiles for our data.

  • ls -l | grep files - ls -l means list directories and files, grep files just filters name of files.

Right now, we have to grant permission for mssql user, which was creted with installation of SQL Server, run following comands:

  • sudo chown mssql /var/opt/mssql/data/datafiles - It is for change owner of directories and files. - For our datafiles directory.

  • sudo chgrp mssql /var/opt/mssql/data/datafiles - It is for change group of directories and files. - For our datafiles directory.

  • and we will provide these two commands for logfiles.


Finally, we can change default directories in SQL Server by following commands:


1) For data directory:

and provide restart of SQL Server.

2) For log directory:

and provide restart of SQL Server.

And that's all. If you want to be sure, you can check again via Management Studio:


Change default locations has been changed successfully.

I hope you enjoy!

70 zobrazení
SIGN UP AND STAY UPDATED!
  • Grey Twitter Icon
  • Grey Facebook Icon
  • Grey LinkedIn Icon

© 2020 All rights reserved. MSSQLONLINUX.com | Filip Holub

  • Twitter Social Icon
  • Facebook Social Icon
  • LinkedIn Social Icon