问题描述
我们有一台运行 SQL Server 2005 的 Windows 机器,我们需要能够从 Linux 机器上运行一些数据库查询.有哪些推荐的方法可以做到这一点?理想情况下,我们需要一个类似于 Windows 上的 sqlcmd 的命令行实用程序.
We have a Windows machine running SQL Server 2005, and we need to be able to run some database queries on it from a Linux box. What are some of the recommended ways of doing this? Ideally, we would want a command-line utility similar to sqlcmd on Windows.
推荐答案
首先安装 FreeTDS,然后配置两个 ODBC 引擎之一以使用 FreeTDS 作为其 ODBC 驱动程序.然后使用ODBC引擎的命令行界面.
Install first FreeTDS, then configure one of the two ODBC engines to use FreeTDS as its ODBC driver. Then use the commandline interface of the ODBC engine.
unixODBC 有 isql,iODBC 有 iodbctest
unixODBC has isql, iODBC has iodbctest
你也可以使用你喜欢的编程语言(我已经成功使用 Perl、C、Python 和 Ruby 连接到 MSSQL)
You can also use your favorite programming language (I've successfully used Perl, C, Python and Ruby to connect to MSSQL)
我个人使用 FreeTDS + iODBC:
I'm personally using FreeTDS + iODBC:
$more /etc/freetds/freetds.conf
[10.0.1.251]
host = 10.0.1.251
port = 1433
tds version = 8.0
$ more /etc/odbc.ini
[ACCT]
Driver = /usr/local/freetds/lib/libtdsodbc.so
Description = ODBC to SQLServer via FreeTDS
Trace = No
Servername = 10.0.1.251
Database = accounts_ver8
这篇关于从 Linux 访问 Microsoft SQL Server 的方法有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!