Install the SQL Server command-line tool on Red Hat

0 Comments

In order to run Transact-SQL statements on the SQL Server. The following SQL Server command-line tools: sqlcmd and bcp. is should be installed

1- Prerequisite

Download the Microsoft Red Hat repository configuration file For RHEL8

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo

remove any older unixODBC packages.

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

2- Install mssql-tools with the unixODBC developer package.

sudo yum install -y mssql-tools unixODBC-devel

3- Add mssql -tool path to your PATH environment variable.

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

4- Connect to SQL Server locally

run sqlcmd with parameter S for server name -U user name and -P for the password

- sqlcmd -S localhost -U SA 
or
- sqlcmd -S localhost -U SA -P '<YourPassword>'

5- Create a new database

CREATE DATABASE TestDB

GO