使用 bash 脚本连接到远程 SQL Server

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22664515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:01:34  来源:igfitidea点击:

Using bash script to connect to remote SQL Server

sql-serverlinuxbashdebian

提问by TrueBlue10

Our company has a db (SQL Server) in another country. I have the host name, username and the password of the db. I want to extract data from the database through bash shell and put them into local file. How can I do that?

我们公司在另一个国家有一个数据库(SQL Server)。我有数据库的主机名、用户名和密码。我想通过bash shell从数据库中提取数据并将它们放入本地文件中。我怎样才能做到这一点?

回答by Liam Gretton

Install FreeTDS. Once configured you'll be able to use tsqlto query SQL Server from bash.

安装FreeTDS。配置完成后,您将能够使用tsql从 bash 查询 SQL Server。

回答by Razvan Stefanescu

You will need some command line utilities export data from MS SQL Server. One option is to install Microsoft ODBC Driver for SQL Server on Linux and then use some command line utility like sqlcmd.

您将需要一些命令行实用程序从 MS SQL Server 导出数据。一种选择是在 Linux 上为 SQL Server 安装 Microsoft ODBC 驱动程序,然后使用一些命令行实用程序,如 sqlcmd。

MSDN page for Microsoft ODBC Driver: http://msdn.microsoft.com/en-us/library/hh568451.aspx

Microsoft ODBC 驱动程序的 MSDN 页面:http: //msdn.microsoft.com/en-us/library/hh568451.aspx

Example of using sqlcmd to export data to a CSV file: How to export data as CSV format from SQL Server using sqlcmd?

使用 sqlcmd 将数据导出到 CSV 文件的示例:如何使用 sqlcmd 从 SQL Server 将数据导出为 CSV 格式?