1、添加安裝源
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 104 0 0:00:01 0:00:01 --:--:-- 104
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo msprod.repo mssql-server.repo
2、安裝 mssql-tools 和 unixODBC 開發人員包
[root@localhost yum.repos.d]# yum install mssql-tools unixODBC-devel
3、將 /opt/mssql-tools/bin/
添加到 PATH 環境變量
[root@localhost /]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile [root@localhost /]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc [root@localhost /]# cd ~ [root@localhost ~]# source .bashrc
4、檢查是否安裝成功:輸入命令 sqlcmd
[root@localhost opt]# sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 17.3.0000.1 Linux
Copyright (c) 2012 Microsoft. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]
[root@localhost opt]#
5、Centos 連接數據庫:
使用 SQL Server 名稱 (-S),用戶名 (-U) 和密碼 (-P) 的參數運行 sqlcmd。 在本教程中,用戶進行本地連接,因此服務器名稱為 localhost
。 用戶名為 SA
,密碼是在安裝過程中為 SA 帳戶提供的密碼。
sqlcmd -S localhost -U SA -P '<YourPassword>'
[root@localhost opt]# sqlcmd -S localhost -U sa -P 'xxxxxxxxxx'
1>