本文基于微软官方文档整理完成
https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-setup-tools
The following steps install the command-line tools, Microsoft ODBC drivers, and their dependencies. The mssql-tools package contains:
- sqlcmd: Command-line query utility.
- bcp: Bulk import-export utility.
Install the tools for your platform:
Install tools on RHEL
Use the following steps to install the mssql-tools on Red Hat Enterprise Linux.
-
Enter superuser mode.
Copy
bash
sudo su
-
Download the Microsoft Red Hat repository configuration file.
Copy
bash
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
-
Exit superuser mode.
Copy
bash
exit
-
If you had a previous version of mssql-tools installed, remove any older unixODBC packages.
Copy
bash
sudo yum update sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
-
Run the following commands to install mssql-tools with the unixODBC developer package.
Copy
bash
sudo yum update sudo yum install mssql-tools unixODBC-devel
Note
To update to the latest version of mssql-tools run the following commands:
Copy
bash
sudo yum check-update sudo yum update mssql-tools
-
Optional: Add
/opt/mssql-tools/bin/
to your PATH environment variable in a bash shell.To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
Copy
bash
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:
Copy
bash
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc