gpt4 book ai didi

linux - 在 UNIX 框中执行 bcp 时出错

转载 作者:太空狗 更新时间:2023-10-29 12:06:42 24 4
gpt4 key购买 nike

目前我正致力于在 Unix 机器上执行 Perl 脚本。 Perl 脚本在内部使用 BCP 命令从 MS-SQL 数据库中获取数据。相同的 perl 脚本在 Windows 中正常运行。但是当我将它执行到 Unix 中时(使用 Putty)。它在控制台上显示以下错误消息。

sh: bcp: command not found

下面是我在 perl 脚本中的 sql 命令。

"bcp \"select drive_id, ilf, xcoord, ycoord 
from $mdtdb\.dbo\.$mdtcentraldtdtable a where
drive_id = $driveid and not exists
(select 'x' from $mdtdb\.dbo\.$mdtcentralaudittable b where
a.drive_id = b.drive_id and a.ilf = b.ilf)\"
queryout $tempdatafile -o $bcpoutfile -S $mdtsvr -q -c -t ,
-U $user1 -P $pw1";

我已成功连接到数据库。

我需要你的帮助来解决上述 bcp 问题。

最佳答案

在 unix 上,有一个用于 sybase 客户端的 bcp 工具。它仅适用于 Sybase 产品。

有一个可用于 MSSQL 服务器的 bcp 的开源替代品:freebcp但是 freetds 库有点难以配置,并且(作为志愿者的逆向工程)它只适用于相对简单的数据类型。

要在基于 ubuntu/debian 的 linux 机器上安装它,运行这个

apt-cache search freetds

freetds-common - configuration files for FreeTDS SQL client libraries
freetds-dev - MS SQL and Sybase client library (static libs and headers)
libct4 - libraries for connecting to MS SQL and Sybase SQL servers
libdbd-freetds - Freetds database server driver for libdbi
libsybdb5 - libraries for connecting to MS SQL and Sybase SQL servers
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers
freetds-bin - FreeTDS command-line utilities
libaprutil1-dbd-freetds - Apache Portable Runtime Utility Library - FreeTDS Driver
sqsh - commandline SQL client for MS SQL and Sybase servers
libqt4-sql-tds - Qt 4 FreeTDS database driver

这个命令是可选的:

apt-file list freetds-bin

freetds-bin: /usr/bin/bsqldb
freetds-bin: /usr/bin/bsqlodbc
freetds-bin: /usr/bin/datacopy
freetds-bin: /usr/bin/defncopy
freetds-bin: /usr/bin/fisql
freetds-bin: /usr/bin/freebcp
freetds-bin: /usr/bin/osql
freetds-bin: /usr/bin/tdspool
freetds-bin: /usr/bin/tsql

这些命令安装了大部分你需要的东西

apt-get install freetds-bin 
apt-get install freetds-dev

然后您必须将您的连接数据输入到配置文件中

/etc/freetds/freetds.conf

[OurMSSQLServer]

host = 1xx.xxx.xxx.xx
port = 1433
tds version = 8.0

也许必须更改此配置文件中的其他内容。这个我现在不记得了。

从这里开始,你就靠自己了。请阅读 freetds 文档:http://www.freetds.org/userguide/

freetds 软件是最新的(积极开发的)。但我认为开发团队非常小。

您也可以从源代码编译 freetds,但这可能需要更多的努力。

关于linux - 在 UNIX 框中执行 bcp 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9177040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com