Prerequisites
You must have an RHEL 7.3-7.8 or 8.0-8.3 computer with a minimum of 2 GB of memory.
Go to https://access.redhat.com/products/red-hat-enterprise-linux/evaluation to install Red Hat Enterprise Linux on your own computer. You can also build RHEL virtual machines in Azure. See Build and manage Linux VMs with Azure CLI, and use—image RHEL in the call to create az VM.
If you've got previously installed a SQL Server CTP or RC release, you want to first uninstall the old repository before these steps are followed. For more detail, see Configure SQL Server 2017 and 2019 Linux repositories.
Install SQL Server
Note :
This command points to the RHEL 8 repository for SQL Server 2019. RHEL 8 does not come with python2, which is needed by SQL Server, preinstalled. Execute the command and verify that python2 is selected as the interpreter before you begin the SQL Server installation steps:
sudo alternatives --config python
# If not configured, install python2 and openssl10 using the subsequent commands:
sudo yum install python2
sudo yum install compat-openssl10
# Configure python2 because the default interpreter using this command:
sudo alternatives --config python
See the following blog about how to install python2 and configure it as the default interpreter for more detail on these steps: https://www.redhat.com/en/blog/install-microsoft-sql-server-red-hat-enterprise-linux-8-beta.
Adjust the path below to /rhel/7 instead of /rhel/8 if you are using RHEL 7.
To configure SQL Server on RHEL, run the subsequent commands during a terminal to put in the mssql-server package:
1. Download the Microsoft SQL Server 2019 Red Hat repository configuration file:
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo
sudo yum install -y mssql-server
3. After the package installation finishes, run mssql-conf setup and follow the prompts to line the SA password and choose your edition.
sudo /opt/mssql/bin/mssql-conf setup
systemctl status mssql-server
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd –reload
At now , SQL Server 2019 is running on your RHEL machine and is prepared to use!
Install the SQL Server command-line tools
You need to connect to a tool that can run Transact-SQL statements on SQL Server to build a database. SQL Server command-line utilities are configured in the following steps: sqlcmd and bcp.
- Download the Microsoft Red Hat repository configuration file.
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
sudo yum install -y mssql-tools unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
Connect locally
sqlcmd -S localhost -U SA -P '<YourPassword>'
3. If you get a connection failure, first plan to diagnose the matter from the error message. Then review the connection troubleshooting recommendations.
Create and query data
The following sections will guide you through the use of sqlcmd to create a new database, add data and run a simple query.
Create a new database
The following steps will create a new database called TestDB.
- To create a test database, paste the following Transact-SQL command from the sqlcmd command prompt:
CREATE DATABASE TestDB
SELECT Name from sys.Databases
GO
Insert data
Next, create a new table, Inventory, and add two new rows.
- Switch context from the sqlcmd command prompt to the new TestDB database:
USE TestDB
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
GO
Select data
- Now, run a query to get the data back from the Inventory table.
1. Within the sqlcmd prompt, enter a question that returns rows from the Inventory table where the number is quite 152:
SELECT * FROM Inventory WHERE quantity > 152;
GO
Exit the sqlcmd command prompt
To end your sqlcmd session, type QUIT:
QUIT
Comments
Post a Comment