安装 Linux 和 macOS 上的 Microsoft ODBC Driver for SQL ServerInstalling the Microsoft ODBC Driver for SQL Server on Linux and macOS

下载下载 ODBC 驱动程序DownloadDownload ODBC Driver

本文介绍如何在 Linux 和 macOS 上安装 MicrosoftMicrosoft ODBC Driver for SQL ServerSQL Server,以及适用于 SQL Server(bcpsqlcmd)和 unixODBC 开发标头的可选命令行工具。This article explains how to install the MicrosoftMicrosoft ODBC Driver for SQL ServerSQL Server on Linux and macOS, as well as the optional Command-Line Tools for SQL Server (bcp and sqlcmd) and the unixODBC Development Headers.

Microsoft ODBC Driver 17 for SQL ServerMicrosoft ODBC Driver 17 for SQL Server

重要

如果安装了暂时可用的 v17 msodbcsql 包,应先删除它,再安装 msodbcsql17 包。If you installed the v17 msodbcsql package that was briefly available, you should remove it before installing the msodbcsql17 package. 这样可避免冲突。This will avoid conflicts. msodbcsql17 包可以与 msodbcsql v13 包并行安装。The msodbcsql17 package can be installed side by side with the msodbcsql v13 package.

DebianDebian

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 10
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list

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

RedHat Enterprise ServerRedHat Enterprise Server

sudo su

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#RedHat Enterprise Server 6
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RedHat Enterprise Server 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RedHat Enterprise Server 8
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo

exit
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel

SUSE Linux Enterprise ServerSUSE Linux Enterprise Server

sudo su

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#SUSE Linux Enterprise Server 11 SP4
#Ensure SUSE Linux Enterprise 11 Security Module has been installed 
zypper ar https://packages.microsoft.com/config/sles/11/prod.repo

#SUSE Linux Enterprise Server 12
zypper ar https://packages.microsoft.com/config/sles/12/prod.repo

#SUSE Linux Enterprise Server 15
zypper ar https://packages.microsoft.com/config/sles/15/prod.repo
#(Only for driver 17.3 and below)
SUSEConnect -p sle-module-legacy/15/x86_64

exit
sudo ACCEPT_EULA=Y zypper install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y zypper install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo zypper install unixODBC-devel

UbuntuUbuntu

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Ubuntu 14.04
curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 16.04
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 18.10
curl https://packages.microsoft.com/config/ubuntu/18.10/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 19.04
curl https://packages.microsoft.com/config/ubuntu/19.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

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

备注

  • Ubuntu 18.04 支持需要 17.2 或更高版本的驱动程序。Driver version 17.2 or higher is required for Ubuntu 18.04 support.
  • Ubuntu 18.10 支持需要 17.3 或更高版本的驱动程序。Driver version 17.3 or higher is required for Ubuntu 18.10 support.

MacOSMacOS

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql17 mssql-tools

Microsoft ODBC Driver 13.1 for SQL ServerMicrosoft ODBC Driver 13.1 for SQL Server

Debian 8Debian 8

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

RedHat Enterprise Server 6RedHat Enterprise Server 6

sudo su
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel

RedHat Enterprise Server 7RedHat Enterprise Server 7

sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install unixODBC-devel

SUSE Linux Enterprise Server 11SUSE Linux Enterprise Server 11

sudo su
zypper ar https://packages.microsoft.com/config/sles/11/prod.repo
exit
sudo ACCEPT_EULA=Y zypper install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y zypper install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo zypper install unixODBC-devel

SUSE Linux Enterprise Server 12SUSE Linux Enterprise Server 12

sudo su
zypper ar https://packages.microsoft.com/config/sles/12/prod.repo
exit
sudo ACCEPT_EULA=Y zypper install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y zypper install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo zypper install unixODBC-devel

Ubuntu 15.10Ubuntu 15.10

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

Ubuntu 16.04Ubuntu 16.04

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

Ubuntu 16.10Ubuntu 16.10

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

OS X 10.11 (El Capitan) 和 macOS 10.12 (Sierra)OS X 10.11 (El Capitan) and macOS 10.12 (Sierra)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql@13.1.9.2 mssql-tools@14.0.6.0

Microsoft ODBC Driver 13 for SQL ServerMicrosoft ODBC Driver 13 for SQL Server

RedHat Enterprise Server 6RedHat Enterprise Server 6

sudo su
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum update
sudo yum remove unixODBC #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql-13.0.1.0-1 mssql-tools-14.0.2.0-1
sudo yum install unixODBC-utf16-devel #this step is optional but recommended*
#Create symlinks for tools
ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

RedHat Enterprise Server 7RedHat Enterprise Server 7

sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum update
sudo yum remove unixODBC #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql-13.0.1.0-1 mssql-tools-14.0.2.0-1
sudo yum install unixODBC-utf16-devel #this step is optional but recommended*
#Create symlinks for tools
ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

Ubuntu 15.10Ubuntu 15.10

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql=13.0.1.0-1 mssql-tools=14.0.2.0-1
sudo apt-get install unixodbc-dev-utf16 #this step is optional but recommended*
#Create symlinks for tools
ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

Ubuntu 16.04Ubuntu 16.04

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql=13.0.1.0-1 mssql-tools=14.0.2.0-1
sudo apt-get install unixodbc-dev-utf16 #this step is optional but recommended*
#Create symlinks for tools
ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

SUSE Linux Enterprise Server 12SUSE Linux Enterprise Server 12

sudo su 
zypper ar https://packages.microsoft.com/config/sles/12/prod.repo 
zypper update 
sudo ACCEPT_EULA=Y zypper install msodbcsql-13.0.1.0-1 mssql-tools-14.0.2.0-1
zypper install unixODBC-utf16-devel
#Create symlinks for tools
ln -sfn /opt/mssql-tools/bin/sqlcmd-13.0.1.0 /usr/bin/sqlcmd 
ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /usr/bin/bcp

脱机安装Offline installation

如果希望/需要在未连接 Internet 的计算机上安装 MicrosoftMicrosoft ODBC Driver 13,则需要手动解析包依赖项。If you prefer/require the MicrosoftMicrosoft ODBC Driver 13 to be installed on a computer with no internet connection, you will need to resolve package dependencies manually. MicrosoftMicrosoft ODBC Driver 13 具有以下直接依赖项:The MicrosoftMicrosoft ODBC Driver 13 has the following direct dependencies:

  • Ubuntu:libc6 (>= 2.21), libstdc++6 (>= 4.9), libkrb5-3, libcurl3, openssl, debconf (>= 0.5), unixodbc (>= 2.3.1-1)Ubuntu: libc6 (>= 2.21), libstdc++6 (>= 4.9), libkrb5-3, libcurl3, openssl, debconf (>= 0.5), unixodbc (>= 2.3.1-1)
  • Red Hat:glibc, e2fsprogs, krb5-libs, openssl, unixODBCRed Hat: glibc, e2fsprogs, krb5-libs, openssl, unixODBC
  • SuSE:glibc, libuuid1, krb5, openssl, unixODBCSuSE: glibc, libuuid1, krb5, openssl, unixODBC

所有这些包都具有自己的依赖项,这些依赖性可能会显示在系统上,也可能不会显示。Each of these packages in turn has their own dependencies, which may or may not be present on the system. 有关此问题的常规解决方案,请参阅分发对应的包管理器文档:RedhatUbuntuSUSEFor a general solution to this issue, refer to your distribution's package manager documentation: Redhat, Ubuntu, and SUSE

还有一种常见做法是,手动下载所有相关包并将其一起放置在安装计算机上,然后依次手动安装每个包,最后安装 MicrosoftMicrosoft ODBC Driver 13 包。It is also common to manually download all the dependent packages and place them together on the installation computer, then manually install each package in turn, finishing with the MicrosoftMicrosoft ODBC Driver 13 package.

Redhat Linux Enterprise Server 7Redhat Linux Enterprise Server 7

yum install glibc e2fsprogs krb5-libs openssl unixODBC unixODBC-devel #install dependencies
sudo rpm -i  msodbcsql-13.1.X.X-X.x86_64.rpm #install the Driver

Ubuntu 16.04Ubuntu 16.04

sudo apt-get install libc6 libstdc++6 libkrb5-3 libcurl3 openssl debconf unixodbc unixodbc-dev #install dependencies
sudo dpkg -i msodbcsql_13.1.X.X-X_amd64.deb #install the Driver

SUSE Linux Enterprise Server 12SUSE Linux Enterprise Server 12

zypper install glibc, libuuid1, krb5, openssl, unixODBC unixODBC-devel #install dependencies
sudo rpm -i  msodbcsql-13.1.X.X-X.x86_64.rpm #install the Driver

完成包安装后,可以通过运行 ldd 并检查其输出是否缺少库来验证 MicrosoftMicrosoft ODBC Driver 13 是否可以找到其所有依赖项:Once you have completed the package installation, you can verify that the MicrosoftMicrosoft ODBC Driver 13 can find all its dependencies by running ldd and inspecting its output for missing libraries:

ldd /opt/microsoft/msodbcsql/lib64/libmsodbcsql-*

Linux 上的 Microsoft ODBC Driver 11 for SQL ServerMicrosoft ODBC Driver 11 for SQL Server on Linux

安装 unixODBC 驱动程序管理器后才能开始使用该驱动程序。Before you can use the driver, install the unixODBC driver manager. 有关详细信息,请参阅安装驱动程序管理器For more information, see Installing the Driver Manager.

安装步骤Installation Steps

重要

这些说明参考了 Red Hat Linux 的安装文件 msodbcsql-11.0.2270.0.tar.gzThese instructions refer to msodbcsql-11.0.2270.0.tar.gz, which is installation file for Red Hat Linux. 如果要安装适用于 SUSE Linux 的预览版,则文件名为 msodbcsql-11.0.2260.0.tar.gzIf you are installing the Preview for SUSE Linux, the file name is msodbcsql-11.0.2260.0.tar.gz.

若要安装该驱动程序:To install the driver:

  1. 请确保具有根权限。Make sure that you have root permission.

  2. 转到下载放置文件 msodbcsql-11.0.2270.0.tar.gz 的目录。Change to the directory where the download placed the file msodbcsql-11.0.2270.0.tar.gz. 确保所拥有的 *.tar.gz 文件与你的 Linux 版本匹配。Make sure that you have the *.tar.gz file that matches your version of Linux. 若要提取文件,请执行以下命令:tar xvzf msodbcsql-11.0.2270.0.tar.gzTo extract the files, execute the following command, tar xvzf msodbcsql-11.0.2270.0.tar.gz.

  3. 转到 msodbcsql-11.0.2270.0 目录,你应在此处看到一个名为 install.sh 的文件 。Change to the msodbcsql-11.0.2270.0 directory and there you should see a file called install.sh.

  4. 若要查看可用安装选项的列表,请执行以下命令: ./install.shTo see a list of the available installation options, execute the following command: ./install.sh.

  5. 创建 odbcinst.ini的备份。Make a backup of odbcinst.ini. 驱动程序安装会更新 odbcinst.iniThe driver installation updates odbcinst.ini. odbcinst.ini 包含在 unixODBC 驱动程序管理器中注册的驱动程序列表。odbcinst.ini contains the list of drivers that are registered with the unixODBC Driver Manager. 若要在计算机上发现 odbcinst.ini 的位置,请执行以下命令:odbc_config --odbcinstiniTo discover the location of odbcinst.ini on your computer, execute the following command: odbc_config --odbcinstini.

  6. 安装该驱动程序之前,请执行以下命令:./install.sh verifyBefore you install the driver, execute the following command: ./install.sh verify. ./install.sh verify 告的输出会报计算机中是否具有在 Linux 上支持 ODBC 驱动程序所需的软件。The output of ./install.sh verify reports if your computer has the required software to support the ODBC driver on Linux.

  7. 当你准备好在 Linux 上安装 ODBC 驱动程序时,请执行命令:./install.sh installWhen you are ready to install the ODBC driver on Linux, execute the command: ./install.sh install. 如果需要指定安装命令(bin-dirlib-dir),请在“安装”选项后指定该命令 。If you need to specify an install command (bin-dir or lib-dir), specify the command after the install option.

  8. 查看许可协议之后,键入 YES 以继续安装。After reviewing the license agreement, type YES to continue with the installation.

安装会将驱动程序放在 /opt/microsoft/msodbcsql/11.0.2270.0 中。Installation puts the driver in /opt/microsoft/msodbcsql/11.0.2270.0. 驱动程序及其支持文件必须位于 /opt/microsoft/msodbcsql/11.0.2270.0 中。The driver and its support files must be in /opt/microsoft/msodbcsql/11.0.2270.0.

若要验证 Linux 上的 Microsoft ODBC 驱动程序是否已成功注册,请执行以下命令:odbcinst -q -d -n "ODBC Driver 11 for SQL Server"To verify that the Microsoft ODBC driver on Linux was registered successfully, execute the following command: odbcinst -q -d -n "ODBC Driver 11 for SQL Server".

对 Linux 上的 ODBC 驱动程序使用现有 MSDN C++ ODBC 示例 会使用 Linux 上的 ODBC 驱动程序显示一个连接到 SQL ServerSQL Server 的代码示例。Use Existing MSDN C++ ODBC Samples for the ODBC Driver on Linux shows a code sample that connects to SQL ServerSQL Server using the ODBC driver on Linux.

卸载Uninstalling

通过执行以下命令,可以卸载 Linux 上的 ODBC 驱动程序 11:You can uninstall the ODBC driver 11 on Linux by executing the following commands:

  1. rm -f /usr/bin/sqlcmd

  2. rm -f /usr/bin/bcp

  3. rm -rf /opt/microsoft/msodbcsql

  4. odbcinst -u -d -n "ODBC Driver 11 for SQL Server"

解决连接问题Troubleshooting Connection Problems

如果使用 ODBC 驱动程序无法连接到 SQL ServerSQL Server ,请使用以下信息确定问题原因。If you are unable to make a connection to SQL ServerSQL Server using the ODBC driver, use the following information to identify the problem.

最常见的连接问题是安装两个 UnixODBC 驱动程序管理器的副本。The most common connection problem is to have two copies of the UnixODBC Driver Manager installed. 搜索 /usr 以查找 libodbc*.so*。Search /usr for libodbc*.so*. 如果看到多个版本的文件,则(可能)安装了多个驱动程序管理器。If you see more than one version of the file, you (possibly) have more than one driver manager installed. 你的应用程序可能会使用错误的版本。Your application might use the wrong version.

通过编辑 /etc/odbcinst.ini 文件以包含具有这些条目的如下部分来启用连接日志:Enable the connection log by editing your /etc/odbcinst.ini file to contain the following section with these items:

[ODBC]
Trace = Yes
TraceFile = (path to log file, or /dev/stdout to output directly to the terminal)

如果连接再次失败并且未看到日志文件,则计算机上(可能)存在两个驱动程序管理器的副本。If you get another connection failure and do not see a log file, there (possibly) are two copies of the driver manager on your computer. 否则,日志输出应该类似于以下内容:Otherwise, the log output should be similar to the following:

[ODBC][28783][1321576347.077780][SQLDriverConnectW.c][290]  
        Entry:  
            Connection = 0x17c858e0  
            Window Hdl = (nil)  
            Str In = [DRIVER={ODBC Driver 13 for SQL Server};SERVER={contoso.com};Trusted_Connection={YES};WSID={mydb.contoso.com};AP...][length = 139 (SQL_NTS)]  
            Str Out = (nil)  
            Str Out Max = 0  
            Str Out Ptr = (nil)  
            Completion = 0  
        UNICODE Using encoding ASCII 'UTF8' and UNICODE 'UTF16LE'  

如果 ASCII 字符编码不是 UTF-8,例如:If the ASCII character encoding is not UTF-8, for example:

UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'  

安装了多个驱动程序管理器并且应用程序使用的是错误的管理器,或者驱动程序管理器未正确构建。There is more than one Driver Manager installed and your application is using the wrong one, or the Driver Manager was not built correctly.

有关解决这种连接失败的详细信息,请参阅:For more information about resolving connection failures, see:

驱动程序文件Driver Files

Linux 和 MacOS 上的 ODBC Driver 由以下组件构成:The ODBC Driver on Linux and MacOS consists of the following components:

LinuxLinux

组件Component 描述Description
libmsodbcsql-17.X.so.X.X 或 libmsodbcsql-13.X.so.X.Xlibmsodbcsql-17.X.so.X.X or libmsodbcsql-13.X.so.X.X 包含该驱动程序所有功能的共享对象 (so) 动态库文件。The shared object (so) dynamic library file that contains all of the driver's functionality. 此文件安装在 ODBC Driver 17 的 /opt/microsoft/msodbcsql17/lib64/ 中和 ODBC Driver 13 的 /opt/microsoft/msodbcsql/lib64/ 中。This file is installed in /opt/microsoft/msodbcsql17/lib64/ for the Driver 17 and in /opt/microsoft/msodbcsql/lib64/ for Driver 13.
msodbcsqlr17.rllmsodbcsqlr13.rllmsodbcsqlr17.rll or msodbcsqlr13.rll 驱动程序库的附带资源文件。The accompanying resource file for the driver library. 此文件安装在 [driver .so directory]../share/resources/en_US/This file is installed in [driver .so directory]../share/resources/en_US/
msodbcsql.hmsodbcsql.h 头文件,它包含使用驱动程序所需的所有新定义。The header file that contains all of the new definitions needed to use the driver.

注意: 你无法在同一个程序中引用 msodbcsql.h 和 odbcss.h。Note: You cannot reference msodbcsql.h and odbcss.h in the same program.

msodbcsql.h 安装在 ODBC Driver 17 的 /opt/microsoft/msodbcsql17/include/ 中和 ODBC Driver 13 的 /opt/microsoft/msodbcsql/include/ 中。msodbcsql.h is installed in /opt/microsoft/msodbcsql17/include/ for Driver 17 and in /opt/microsoft/msodbcsql/include/ for Driver 13.
LICENSE.txtLICENSE.txt 包含最终用户许可协议条款的文本文件。The text file that contains the terms of the End-User License Agreement. 此文件位于 ODBC Driver 17 的 /usr/share/doc/msodbcsql17/ 中和 ODBC Driver 13 的 /usr/share/doc/msodbcsql/ 中。This file is placed in /usr/share/doc/msodbcsql17/ for Driver 17 and in /usr/share/doc/msodbcsql/ for Driver 13.
RELEASE_NOTESRELEASE_NOTES 包含发行说明的文本文件。The text file that contains release notes. 此文件位于 ODBC Driver 17 的 /usr/share/doc/msodbcsql17/ 中和 ODBC Driver 13 的 /usr/share/doc/msodbcsql/ 中。This file is placed in /usr/share/doc/msodbcsql17/ for Driver 17 and in /usr/share/doc/msodbcsql/ for Driver 13.

MacOSMacOS

组件Component 描述Description
libmsodbcsql.17.dylib 或 libmsodbcsql.13.dyliblibmsodbcsql.17.dylib or libmsodbcsql.13.dylib 包含该驱动程序所有功能的动态库 (dylib) 文件。The dynamic library (dylib) file that contains all of the driver's functionality. 此文件安装在 /usr/local/lib/ 中。This file is installed in /usr/local/lib/.
msodbcsqlr17.rllmsodbcsqlr13.rllmsodbcsqlr17.rll or msodbcsqlr13.rll 驱动程序库的附带资源文件。The accompanying resource file for the driver library. 此文件安装在 ODBC Driver 17 的 [driver .dylib directory]../share/msodbcsql17/resources/en_US/ 中和 ODBC Driver 13 的 [driver .dylib directory]../share/msodbcsql/resources/en_US/ 中。This file is installed in [driver .dylib directory]../share/msodbcsql17/resources/en_US/ for Driver 17 and in [driver .dylib directory]../share/msodbcsql/resources/en_US/ for Driver 13.
msodbcsql.hmsodbcsql.h 头文件,它包含使用驱动程序所需的所有新定义。The header file that contains all of the new definitions needed to use the driver.

注意: 你无法在同一个程序中引用 msodbcsql.h 和 odbcss.h。Note: You cannot reference msodbcsql.h and odbcss.h in the same program.

msodbcsql.h 安装在 ODBC Driver 17 的 /usr/local/include/msodbcsql17/ 中和 ODBC Driver 13 的 /usr/local/include/msodbcsql/ 中。msodbcsql.h is installed in /usr/local/include/msodbcsql17/ for Driver 17 and in /usr/local/include/msodbcsql/ for Driver 13.
LICENSE.txtLICENSE.txt 包含最终用户许可协议条款的文本文件。The text file that contains the terms of the End-User License Agreement. 此文件位于 ODBC Driver 17 的 /usr/local/share/doc/msodbcsql17/ 中和 ODBC Driver 13 的 /usr/local/share/doc/msodbcsql/ 中。This file is placed in /usr/local/share/doc/msodbcsql17/ for Driver 17 and in /usr/local/share/doc/msodbcsql/ for Driver 13.
RELEASE_NOTESRELEASE_NOTES 包含发行说明的文本文件。The text file that contains release notes. 此文件位于 ODBC Driver 17 的 /usr/local/share/doc/msodbcsql17/ 中和 ODBC Driver 13 的 /usr/local/share/doc/msodbcsql/ 中。This file is placed in /usr/local/share/doc/msodbcsql17/ for Driver 17 and in /usr/local/share/doc/msodbcsql/ for Driver 13.

资源文件加载Resource File Loading

驱动程序需要加载资源文件才能正常运行。The driver needs to load the resource file in order to function. 此文件称为 msodbcsqlr17.rllmsodbcsqlr13.rll,具体取决于驱动程序版本。This file is called msodbcsqlr17.rll or msodbcsqlr13.rll depending on the driver version. .rll 文件的位置与驱动程序本身的位置(sodylib)相对,如上表中所述。The location of the .rll file is relative to the location of the driver itself (so or dylib), as noted in the table above. 自版本 17.1 开始,如果从相对路径加载失败,驱动程序还将尝试从默认目录加载 .rllAs of version 17.1 the driver will also attempt to load the .rll from the default directory if loading from the relative path fails. 默认资源文件路径为:The default resource file paths are:

Linux:/opt/microsoft/msodbcsql17/share/resources/en_US/Linux: /opt/microsoft/msodbcsql17/share/resources/en_US/

MacOS:/usr/local/share/msodbcsql17/resources/en_US/MacOS: /usr/local/share/msodbcsql17/resources/en_US/

另请参阅See Also

安装驱动程序管理器Installing the Driver Manager

发行说明Release Notes

系统要求System Requirements