Documente Academic
Documente Profesional
Documente Cultură
Introduction
Pre-requisites
Packages installations : server and client tools
Server engine installation
Client tools installation
Building and running the MS SQL Server instance
Configuring the SQL Server instance
Running mssql-conf setup
Connecting to the SQL Server engine with sqlcmd
Default settings : collation, port
Service mssql-server : start, stop, status
Connecting from a Windows client
Cross platforms data transfers Windows / Linux (backup, restore, bcp)
Backup / Restore
CREATE DATABASE FOR ATTACH
bcp out / in with Unicode data from Windows to Linux
Conclusion
This page has been translated from the french version by non english speakers. Feel
free to help us to translate if you read any grammar or syntax errors by using the
contact form. You're welcome.
Introduction
Who would have believed in 2009, ten years ago, Microsoft SQL Server 2019 on Linux Platforms. Definitely not the
author of this article, but Microsoft did it !
SQL Server 2017 was already supported on Linux platforms, but many features were missing compared to Windows
version like replication, high avalaibility and mirroring, distributed transaction coordinator (DTC), some active
directory authentication mechanisms and SQL Server agent functionalities... List of SQL Server 2017 missing
features on Linux ( https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-release-notes?view=sql-server-
2017#Unsupported ) .
SQL Server 2019 on Linux platforms now include the major missing features in SQL Server 2017. So let's explore
SQL Server 2019 on Linux.
SQL Server 2019 is installed on Ubuntu 18.04 in this article : only Ubuntu 16.04 is supported, but it works on
Ubuntu 18.04 for test purposes.
Multiples instances and named instances are not (yet ?) supported on Linux platforms, third party architectures like
Docker must be used to do so.
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 1/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
In this article, a standalone SQL Server instance is installed. As almost companies implement firewall rules that
prevent servers from communicating with the outside world, offline installations are performed with the packages
*.deb provided by Microsoft.
The SQL Server engine listens on port 1433 and runs with the user mssql.
Database files are not installed in the default directory.
SQL Server agent, SSL and active directory authentication are not covered here.
Restore a database on Linux SQL Server 2019 from a windows SQL Server 2016 database backup.
Export/import a table with bcp in native mode from SQL Server 2016 Windows to SQL Server 2019 Linux.
These 2 tests will show if it is easy to migrate from SQL Server 2016 on Windows to SQL Server 2019 on Linux.
Pre-requisites
The system requirements are the following for SQL Server 2019 on Linux platforms :
Memory : 2GB
File system type : XFS or EXT4
Disk space : 6 GB
Processor speed : 2 GHz
Processor cores : 2
Processor type : x64
Use the command fsck or mount to check file system types where SQL Server will be installed :
fsck -N /dev/sda1
The SQL Server 2019 setup will create an account mssql if it does not exist. If you work in environments with
normalized id for accounts, prepare in advance the account mssql, that's the case here :
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 2/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
Download first the package mssql-server from Microsoft web site. For this package choose Ubuntu 16.04 even if the
target system is Ubuntu 18.04 : https://packages.microsoft.com/ubuntu/16.04/ (
https://packages.microsoft.com/ubuntu/16.04/ ) . The package SQL Server 2019 CTP 3 (mssql-server_15.0.1600.8-
1_amd64.deb) is in the subdirectory ./mssql-server-preview/pool/main/m/mssql-server
Upload the package to the Ubuntu server and check first the dependencies :
Few dependencies, but some are very important : openssl >= 1.0.1g and python >= 2.7.0
+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+
About the installation, all binaries (sqlservr...) and librairies are installed in /opt/mssql (owner : root). Maybe SQL
Server could be installed elsewhere, but it's better here to avoid complicated methods (fakeroot...) for a technology
preview on a non supported Ubuntu version, especially if we plan to upgrade to a newer version in the next weeks.
/opt/mssql/bin
/opt/mssql/lib
A directory /var/opt/mssql is also created (owner mssql). This directory contains the configuration file mssql.conf of
the future instance. At this stage, only one entry in this file : sqlagent disabled.
/var/opt/mssql/mssql.conf
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 3/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
[sqlagent]
enabled = false
About client tools, install the packages in the following order below due to the dependencies :
msodbcsql17 : ./msodbcsql17/msodbcsql17_17.3.1.1-1_amd64.deb.
mssql-tools : ./mssql-tools/mssql-tools_17.3.0.1-1_amd64.deb.
then install MS SQL Server ODBC Driver and MS SQL Server client tools packages :
Microsoft ODBC SQL driver 17 is then installed in the directory /opt/microsoft/msodbcsql17 and MS SQL Server tools
(sqlcmd and bcp) in the directory /opt/mssql-tools/bin.
For an ease of use of sqlcmd and bcp, add the directory /opt/mssql-tools/bin in the environment variable $PATH for
the user mssql. This can be done in the files $HOME/.bashrc and $HOME/.profile.
$HOME/.bashrc, $HOME/.profile
export PATH="$PATH:/opt/mssql-tools/bin"
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 4/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
Before building the instance, many options can be prepared (for example the database locations...).
...
filelocation.defaultdatadir Default directory for data files
...
filelocation.defaultlogdir Default directory for log files
filelocation.errorlogfile Error log file location
filelocation.masterdatafile Master database data file location
filelocation.masterlogfile Master database log file location
...
Without any custom configuration before running mssql-conf setup, database files are created by default in the
directory /var/opt/mssql. That's not what we may want, especially if we split data files and transaction log files on
separate devices, or simply store these ones on LUN SAN.
So configuration must be done before, especially database file locations. Obviously for every custom directory, the
owner must be mssql.
Each custom parameter is written in the configuration file /var/opt/mssql/mssql.conf. This configuration file replaces
the Windows registry database for most of the parameters (default datadir...)
/var/opt/mssql/mssql.conf
[sqlagent]
enabled = false
[filelocation]
defaultdatadir = /sqlpac/mssql/dbfiles
defaultlogdir = /sqlpac/mssql/tlogfiles
masterdatafile = /sqlpac/mssql/system/master.mdf
masterlogfile = /sqlpac/mssql/system/mastlog.ldf
errorlogfile = /software/mssql/mssql-2019-ctp3/log/errorlog
defaultbackupdir = /software/mssql/mssql-2019-ctp3/backup
defaultdumpdir = /software/mssql/mssql-2019-ctp3/crashdump
[errorlog]
numerrorlogs = 10
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 5/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
Everything is ready : server, client packages and configuration. Let's build the instance with mssql-conf and the
option setup.
select @@version
go
The Ubuntu server is installed in English, but what is the default collation setting then ? The collation applied is
SQL_Latin1_General_CP1_CI_AS.
name collation_name
------------ -----------------------------------------------
master SQL_Latin1_General_CP1_CI_AS
exec sp_helpsort
go
Use /opt/mssql/bin/mssql-conf set-collation to change the collation for system databases if necessary.
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 6/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
The SQL Server service runs with no surprise on the default port 1433 with the account mssql:
By default, the number of SQL Server processes (sqlservr) depends on the number of cores, here 2 cores :
A service mssql-server is automatically created and enabled, the usual commands are available to start, stop, restart
and view the status of the SQL Server service :
Obviously, enabling or disabling the SQL Server service is available like any other service.
If the Ubuntu firewall ufw is configured to deny incoming connexions by default, don't forget to open SQL Server port
1433 :
Rule added
Rule added (v6)
Tests have been performed with SQL Server Management Studio 17.2 (SSMS 17.2) :
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 7/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
No immediate issues, but errors occur while trying a reverse engineering (for example, right click on a table : Script
Table as ➤ CREATE To ➤ New Query Query Editor).
Use SSMS 18, now available (GA), the first fully aware of SQL Server 2019 (compatibility level 150). As usual, setup
very long, many issues encountered and many depending applications installed (.NET Framework 4.7.2, Visual
Studio Isolated Shell 2017 for SSMS, Microsoft Visual Studio Tools for Applications 2017...).
■ Backup / Restore
Test has been done to restore the backup of the demo database AdventureworksDW2016CTP3 coming from Windows
SQL Server 2016. Everything is OK ! No extra steps to perform in this cross-platform context, dbcc checkdb
command did not raise any exception. Further more, migration to SQL Server 2019 is done normally as if we were
working in Windows platform.
dbcc checkdb('AdventureworksDW')
go
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 8/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
About attaching a database with data and transaction log files coming from Windows SQL Server 2016, same results
: no issue and the migration is completed.
Converting database 'AdventureworksDW' from version 852 to the current version 902.
...
Database 'AdventureworksDW' running the upgrade step from version 901 to version 902.
In a windows SQL Server 2016, some unicode data are inserted in a table named t_bcp_unicode in order to test a
transfer with bcp out / in in native mode.
Data are exported in a file with bcp SQL Server 2016 in native mode :
The import in SQL Server 2019 / Linux is then performed without any issue :
use sqlpac
go
select * from t_bcp_unicode
go
lang comment
-------------------- -----------------------------------
FR Une rue française
DE eine Straße
CH 一条街
RU улица
GR ένα δρόμο
Conclusion
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 9/10
12/3/2019 Microsoft SQL Server 2019 on Linux Ubuntu 18.04, installation and configuration
Named instances and multiple instances are not (yet ?) possible, but it is quite easy to build SQL Server on Linux.
Further more, SQL Server databases can be loaded or attached from windows environments with no extra steps, this
is not really surprising as Windows and Linux are both "Little Endian" type platforms (right-to-left byte numbering).
Unfortunately, benchmarks could not be performed, machines with the same hardware characteristics were not
available, but there is a great article about it (in French) : Microsoft SQL Server 2017 plus rapide sous Linux que
Windows ? Pas si sûr… ( https://sqlpro.developpez.com/tutoriels/comparatif-performances-sql-server-windows-linux/
)
Other resources
https://www.sqlpac.com/referentiel/docs-en/ms-sql-2019-linux-ubuntu-18.04-installation-configuration.html#mozTocId751172 10/10