In this quickstart, you install SQL Server 2017 (14.x) on Red Hat Enterprise Linux (RHEL) 8.x. 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 Red Hat Enterprise Linux (RHEL) 8.x. 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 Red Hat Enterprise Linux (RHEL) 8.x or 9.x. Then you can connect with sqlcmd to create your first database and run queries.
This tutorial requires user input and an internet connection. If you're interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux. If you choose to have a preinstalled SQL Server VM on RHEL ready to run your production-based workload, follow the best practices for creating the SQL Server VM.
Azure Marketplace images
You can create your VM based on the following Azure Marketplace image:
When you use the above marketplace 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 RHEL using the above Marketplace images, are fully supported by both Microsoft and Red Hat.
You can configure SQL Server on Linux with mssql-conf, using the following command:
sudo /opt/mssql/bin/mssql-conf setup
Prerequisites
You must have a RHEL 8.x machine with at least 2 GB of memory.
The following commands for installing SQL Server point to the RHEL 8 repository. RHEL 8 doesn't come preinstalled with python2, which is required by SQL Server. Before you begin the SQL Server install steps, execute the command and verify that python2 is selected as the interpreter:
sudo alternatives --config python
# If not configured, install python2 and openssl10 using the following commands:
sudo yum install python2
sudo yum install compat-openssl10
# Configure python2 as the default interpreter using this command:
sudo alternatives --config python
After the package installation finishes, run mssql-conf setup using its full path, 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
To allow remote connections, open the SQL Server port on the RHEL firewall. The default SQL Server port is TCP 1433. If you're using FirewallD for your firewall, you can use the following commands:
At this point, SQL Server is running on your RHEL machine and is ready to use!
The following commands for installing SQL Server point to the RHEL 8 repository. RHEL 8 doesn't come preinstalled with python2, which is required by SQL Server. Before you begin the SQL Server install steps, execute the command and verify that python2 is selected as the interpreter:
sudo alternatives --config python
# If not configured, install python2 and openssl10 using the following commands:
sudo yum install python2
sudo yum install compat-openssl10
# Configure python2 as the default interpreter using this command:
sudo alternatives --config python
After the package installation finishes, run mssql-conf setup using its full path, 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
To allow remote connections, open the SQL Server port on the RHEL firewall. The default SQL Server port is TCP 1433. If you're using FirewallD for your firewall, you can use the following commands:
After the package installation finishes, run mssql-conf setup using its full path, 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
To allow remote connections, open the SQL Server port on the RHEL firewall. The default SQL Server port is TCP 1433. If you're using FirewallD for your firewall, you can use the following commands:
At this point, SQL Server is running on your RHEL machine and is ready to use!
Starting with RHEL 9, you can run SQL Server as a confined application with SELinux enabled. For more information about confined and unconfined applications with SELinux, see Getting started with SELinux.
To run SQL Server as a confined application, follow these steps:
Optionally, if you want to run SQL Server as a confined application, install the mssql-server-selinux package, which enables custom policies.
sudo yum install -y mssql-server-selinux
After the package installation finishes, run mssql-conf setup using its full path, 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
To allow remote connections, open the SQL Server port on the RHEL firewall. The default SQL Server port is TCP 1433. If you're using FirewallD for your firewall, you can use the following commands:
At this point, SQL Server is running on your RHEL 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 Red Hat Enterprise Linux.
Download the Microsoft Red Hat repository configuration file.
For Red Hat 9, use the following command:
curl https://packages.microsoft.com/config/rhel/9/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
For Red Hat 8, use the following command:
curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
For Red Hat 7, use the following command:
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
If you had a previous version of mssql-tools installed, remove any older unixODBC packages.
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.
Check and configure source repositories for SQL Server on Linux. The source repository affects the version of SQL Server that is applied during installation and upgrade.
This article contains the release notes and supported features for SQL Server 2022 running on Linux. Release notes include the most recent release and several previous releases.