In this quickstart, you install SQL Server 2017 (14.x) on Ubuntu 18.04. Then you can connect with sqlcmd to create your first database and run queries.
In this quickstart, you install SQL Server 2019 (15.x) on Ubuntu 20.04. Then you can connect with sqlcmd to create your first database and run queries.
In this quickstart, you install SQL Server 2022 (16.x) on Ubuntu 20.04 or 22.04. Then you can connect with sqlcmd to create your first database and run queries.
If you choose to have a preinstalled SQL Server virtual machine (VM) on Ubuntu ready to run your production-based workload, then follow the best practices for creating the SQL Server VM.
Azure Marketplace images
You can create your VM based on one of the following two Azure Marketplace images:
When you use these images, you avoid the installation step, and can directly configure the instance by providing the SKU and the sa password needed to get started with SQL Server. SQL Server Azure VMs deployed on Ubuntu Pro using the above Marketplace images, are fully supported by both Microsoft and Canonical.
You can configure SQL Server on Linux with mssql-conf, using the following command:
sudo /opt/mssql/bin/mssql-conf setup
Azure Marketplace image
You can create your VM based on the following Azure Marketplace image: Ubuntu 20.04.
When you use this image, you avoid the installation step, and can directly configure the instance by providing the SKU and the sa password needed to get started with SQL Server. SQL Server Azure VMs deployed on Ubuntu Pro using the above Marketplace images, are fully supported by both Microsoft and Canonical.
You can configure SQL Server on Linux with mssql-conf, using the following command:
sudo /opt/mssql/bin/mssql-conf setup
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Prerequisites
You must have an Ubuntu 18.04 machine with at least 2 GB of memory.
After the package installation finishes, run mssql-conf setup and follow the prompts to set the sa password and choose your edition. As a reminder, the following SQL Server editions are freely licensed: Evaluation, Developer, and Express.
sudo /opt/mssql/bin/mssql-conf setup
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Once the configuration is done, verify that the service is running:
systemctl status mssql-server --no-pager
If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.
Import the public repository GPG keys:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
After the package installation finishes, run mssql-conf setup and follow the prompts to set the sa password and choose your edition. As a reminder, the following SQL Server editions are freely licensed: Evaluation, Developer, and Express.
sudo /opt/mssql/bin/mssql-conf setup
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Once the configuration is done, verify that the service is running:
systemctl status mssql-server --no-pager
If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.
After the package installation finishes, run mssql-conf setup and follow the prompts to set the sa password and choose your edition. As a reminder, the following SQL Server editions are freely licensed: Evaluation, Developer, and Express.
sudo /opt/mssql/bin/mssql-conf setup
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Once the configuration is done, verify that the service is running:
systemctl status mssql-server --no-pager
If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.
Download the public key, convert from ASCII to GPG format, and write it to the required location:
After the package installation finishes, run mssql-conf setup and follow the prompts to set the sa password and choose your edition. As a reminder, the following SQL Server editions are freely licensed: Evaluation, Developer, and Express.
sudo /opt/mssql/bin/mssql-conf setup
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Once the configuration is done, verify that the service is running:
systemctl status mssql-server --no-pager
If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.
At this point, SQL Server is running on your Ubuntu machine and is ready to use.
Disable the SA account as a best practice
When you connect to your SQL Server instance using the system administrator (sa) account for the first time after installation, it's important for you to follow these steps, and then immediately disable the sa account as a security best practice.
Create a new login, and make it a member of the sysadmin server role.
Depending on whether you have a container or non-container deployment, enable Windows authentication, and create a new Windows-based login and add it to the sysadmin server role.
Otherwise, create a login using SQL Server authentication, and add it to the sysadmin server role.
Connect to the SQL Server instance using the new login you created.
Disable the sa account, as recommended for security best practice.
Install the SQL Server command-line tools
To create a database, you need to connect with a tool that can run Transact-SQL statements on SQL Server. The following steps install the SQL Server command-line tools: sqlcmd utility and bcp utility.
Use the following steps to install the mssql-tools18 on Ubuntu.
Note
Ubuntu 18.04 is supported starting with SQL Server 2019 (15.x) CU 3.
Ubuntu 20.04 is supported starting with SQL Server 2019 (15.x) CU 10.
Import the public repository GPG keys.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
Register the Microsoft Ubuntu repository.
For Ubuntu 22.04, use the following command:
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
For Ubuntu 20.04, use the following command:
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
For Ubuntu 18.04, use the following command:
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
For Ubuntu 16.04, use the following command:
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
Update the sources list and run the installation command with the unixODBC developer package.
To make sqlcmd and bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
The following steps use sqlcmd to locally connect to your new SQL Server instance.
Caution
Your password should follow the SQL Server default password policy. By default, the password must be at least eight characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. Passwords can be up to 128 characters long. Use passwords that are as long and complex as possible.
Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you connect locally, so the server name is localhost. The user name is sa and the password is the one you provided for the sa account during setup.
sqlcmd -S localhost -U sa -P '<password>'
Note
Newer versions of sqlcmd are secure by default. For more information about connection encryption, see sqlcmd utility for Windows, and Connecting with sqlcmd for Linux and macOS. If the connection doesn't succeed, you can add the -No option to sqlcmd to specify that encryption is optional, not mandatory.
You can omit the password on the command line to be prompted to enter it.
If you later decide to connect remotely, specify the machine name or IP address for the -S parameter, and make sure port 1433 is open on your firewall.
If successful, you should get to a sqlcmd command prompt: 1>.
A cross-platform command-line interface for running Transact-SQL commands.
Connect from Windows
SQL Server tools on Windows connect to SQL Server instances on Linux in the same way they would connect to any remote SQL Server instance.
If you have a Windows machine that can connect to your Linux machine, try the same steps in this topic from a Windows command-prompt running sqlcmd. You must use the target Linux machine name or IP address rather than localhost, and make sure that TCP port 1433 is open on the SQL Server machine. If you have any problems connecting from Windows, see connection troubleshooting recommendations.
For other tools that run on Windows but connect to SQL Server on Linux, see:
Did you know that you can edit SQL content yourself? If you do so, not only do you help improve our documentation, but you also get credited as a contributor to the page.
SQL Server now runs on your choice of operating system. In this learning path, you'll discover the fundamentals of SQL Server on Linux, before discovering how to run SQL Server on Linux containers and deploy SQL Server on Linux. You'll then learn how to automatically tune your SQL Server on Linux deployment.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.