Server/Linux

ubuntu 20.04 mssql odbc driver installation

달빛에취하다 2022. 3. 28. 11:32

 

1. apt-add-repository 가 없는 경우 설치

sudo apt -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates

 

2. apt repository 등록 ( source list )
   출처 : Linux Software Repository for Microsoft Products | Microsoft Docs

curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc

sudo apt-add-repository https://packages.microsoft.com/ubuntu/20.04/prod

sudo apt-get update

 

3. Microsoft ODBC Driver for SQL Server 설치

   출처 : Microsoft ODBC Driver for SQL Server 설치(Linux) - ODBC Driver for SQL Server | Microsoft Docs

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev

 

4. 파일 경로  /etc/odbc.ini

cat /etc/odbcinst.ini

cat /etc/odbcinst.ini 
명령으로 Driver 버전 확인하여 아래 파일 편집시 사용

[mssql] # dns 명칭
Driver = ODBC Driver 18 for SQL Server
Server = DB IP (x.x.x.x)
Port = 1433                                     
Database= DBname

 

5. odbc.ini 파일 수정 후 다시로드

odbcinst -q -d

 

6. 테스트

# unixODBC에서 제공하는 isql 명령어 사용  isql dns
isql mssql

# 비밀번호에 특수 문자가 있는 경우 ' 로 묶어서 사용
isql mssql username passwords -v

 

7. 추가사항

6번 테스트 시 아래와 같은 오류가 발생하는 경우

[08001][unixODBC][Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:self signed certificate]

 

4번에 TrustServerCertificate=yes 추가

[mssql] # dns 명칭
Driver = ODBC Driver 18 for SQL Server
Server = DB IP (x.x.x.x)
Port = 1433                                     
Database= DBname
TrustServerCertificate=yes