Quickstart: Installing SQL Server on Red Hat and create a database
Suitable for: is SQL Server (only Linux) Azure SQL database Azure Synapse Analytics (SQL DW) Parallel Data Warehouse
This quick start describes how to install SQL Server 2019 on 8 in Red Hat Enterprise Linux (RHEL). Then use sqlcmd to connect, first create a database and run the query.
prompt
This tutorial requires user input and an Internet connection. If unattended or offline are interested in the installation process, see the Installation Guide for SQL Server on Linux .
prerequisites
You must have 8 or RHEL 7.3,7.4,7.5,7.6 computer (memory of at least at least 2 GB).
To install Red Hat Enterprise Linux on your computer, go to https://access.redhat.com/products/red-hat-enterprise-linux/evaluation . You can also create RHEL virtual machine in Azure. See created using Azure CLI and manage Linux VM and for az vm create
use in the call --image RHEL
.
If you previously CTP or RC version of SQL Server installed, you must first delete the old store, and then follow these steps. For more information, see Configuring Linux repository for SQL Server 2017 and 2019 .
For additional system requirements, see System Requirements for SQL Server on Linux .
Installing SQL Server
Remark
The following commands for SQL Server 2019 point to RHEL 8 repository. RHEL 8 not pre-install the required SQL Server python2. For more information, see the following blog to learn how to install and configure default python2 interpreter: https://www.redhat.com/en/blog/installing-microsoft-sql-server-red-hat-enterprise- Beta-8-Linux .
If you are using RHEL 7, add the following path to change /rhel/7
instead /rhel/8
.
To configure SQL Server on RHEL, run the following command to install the mssql-server package in the terminal:
-
Download Microsoft SQL Server 2019 Red Hat repository configuration file:
bashsudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo
-
Run the following command to install the SQL Server:
bashsudo yum install -y mssql-server
-
After the package installation is complete, run the mssql-conf setup, follow the prompts to set the SA password, and select the version.
bashsudo /opt/mssql/bin/mssql-conf setup
Remark
Be sure to specify a strong password for the SA account (at least eight characters, including uppercase and lowercase letters, decimal numbers and / or non-alphanumeric symbols).
-
Once configured, verify that the service is running:
bashsystemctl status mssql-server
-
To allow remote connections, open SQL Server ports on RHEL firewall. The default SQL Server port TCP 1433. If you are using a firewall FirewallD, you can use the following command:
bashsudo firewall-cmd --zone=public --add-port=1433/tcp --permanent sudo firewall-cmd --reload
At this point, SQL Server 2019 are running RHEL on your computer, ready to be used!
Installing SQL Server command-line tool
To create the database, you need to use tools to run Transact-SQL statements on the SQL Server to connect. The following steps will install SQL Server command-line tool: the sqlcmd and BCP .
-
Download Microsoft Red Hat repository configuration file.
bashsudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo
-
If you have an earlier version of mssql-tools to install, remove all old unixODBC package.
bashsudo yum remove unixODBC-utf16 unixODBC-utf16-devel
-
Run the following command to use the unixODBC developer packages installed mssql-tools.
bashsudo yum install -y mssql-tools unixODBC-devel
-
For convenience, add to the PATH environment variable
/opt/mssql-tools/bin/
. This can run these tools without specifying a full path. Run the following command to modify the path login sessions and interactive / non-login session:bashecho 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
local connection
The following steps use sqlcmd local connection to the new SQL Server instance.
-
Using SQL Server name (-S), user name (-U) and password (-P) argument run sqlcmd. In this tutorial, locally connected users, the server name
localhost
. User nameSA
, password is the password provided for the SA account during the installation process.bashsqlcmd -S localhost -U SA -P '<YourPassword>'
prompt
You may omit the password on the command line, in order to receive a password prompt.
prompt
If you later decide to connect remotely, specify the -S parameter of the computer name or IP address, and make sure that port 1433 on the firewall is turned on.
-
If successful, it should show sqlcmd command prompt:
1>
. -
If the connection fails, first try to diagnose the problem described in the error message. And then view connection troubleshooting advice .
Create and query data
The following sections describe how to use sqlcmd will gradually create a new database, add data and run a simple query.
New Database
The following steps create a named TestDB
the new database.
-
At the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:
SQLCREATE DATABASE TestDB
-
On the next line, write a query to return the names of all databases on the server:
SQLSELECT Name from sys.Databases
-
The first two orders are not executed immediately. You must type in a new line
GO
to execute the previous command:SQLGO
prompt
To learn more about how to write Transact-SQL statements and queries, see Tutorial: Writing Transact-SQL statement .
Insert data
Next, create a new table Inventory
, and then insert two new rows.
-
In sqlcmd command prompt, the context switch to the new
TestDB
database:SQLUSE TestDB
-
Create a file named
Inventory
new table:SQLCREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
-
Insert data into the new table:
SQLINSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
-
To execute the above command type
GO
:SQLGO
Select Data
Now, in order to run a query from the Inventory
return data table.
-
Sqlcmd command prompt by entering a query, to return
Inventory
the table number of rows is greater than 152:SQLSELECT * FROM Inventory WHERE quantity > 152;
-
Execute this command:
SQLGO
Sqlcmd command prompt exit
To end the sqlcmd session, type QUIT
:
QUIT
Performance Best Practices
After installing SQL Server on Linux, please view the configuration of Linux and SQL Server best practices to improve production performance. For more information, see the Performance Best Practices and Configuration Guide SQL Server on Linux .
Cross-platform Data Tools
In addition to "sqlcmd", you can also use the following cross-platform tools to manage SQL Server:
Azure Data Studio | Cross-platform GUI database management utility. |
Visual Studio Code | A cross-platform GUI code editor that uses mssql extended run Transact-SQL statements. |
PowerShell Core | Cmdlet-based cross-platform automation and configuration tools. |
mssql-cli | Cross-platform Transact-SQL commands used to run a command line interface. |
Connection from Windows
SQL Server tools on Windows connected to a Linux instance of SQL Server, the operating mode and connect to any remote SQL Server instance of the same.
If you have a Windows computer can connect to a Linux computer, run sqlcmd from the Windows command prompt, try to execute the same steps in this topic. Only validates the use of Linux is the target computer name or IP address instead of localhost, and ensure that TCP port 1433 is open. If there is any connection from a Windows problem, see connection troubleshooting suggestions .
About running on Windows, but other tools to connect to SQL Server on Linux, see:
Other deployment scenarios
For additional installation programs, see the following resources:
upgrade | Learn how to upgrade an existing SQL Server version of Linux installed |
Uninstall | Uninstall SQL Server on Linux |
Unattended Setup | Learn how to write the silent installation script |
Offline installation | Learn how to manually download the offline installer package |