有人在这方面取得过成功吗?网上没有太多的参考资料,我已经在谷歌上找到了所有相关的结果。这是我的脚本:
#!/usr/bin/perl
use DBI;
use DBD::ODBC;
$user = "user";
$pw = "pw";
$ip = "192.168.1.0"
#DBI->trace(DBD::ODBC->parse_trace_flags('odbconnection'));
#my $connect_attrs = { PrintError => 0, RaiseError => 1, AutoCommit => 1 };
my $dbh = DBI->connect("dbi:ODBC:$ip", $user, $pw);
错误消息:
DBI connect('192.168.1.0','user',...) failed: (no error string) at ./teradata.pl line 13
注释掉的两行是我之前连接到DB的无果尝试的剩余部分。
UPDATE:以下是我之前对DBD模块所做的工作。
#!/usr/bin/perl
use DBI;
$user = "xxxx";
$pw = "xxxx";
my $dbh = DBI->connect("dbi:Teradata:tdsn", $user, $pw);
错误:
DBI connect('tdsn','xxxx',...) failed: Unable to get host address. at ./teradata.pl line 12
第二次尝试:
#!/usr/bin/perl
use DBI;
$user = "xxxx";
$pw = "xxxx";
my $dbh = DBI->connect("dbi:Teradata:192.168.1.0", $user, $pw);
错误:
DBI connect('192.168.1.0','xxxx',...) failed: Deprecated logons are not allowed by administrator. Upgrade client software to latest version. at ./teradata.pl line 12
第三
#!/usr/bin/perl
use DBI;
use DBD::ODBC;
$user = "xxxx";
$pw = "xxxx";
my $dbh = DBI->connect("dbi:ODBC:tdsn", $user, $pw);
.odbc.ini
[ODBC]
InstallDir = /usr/odbc
Trace = 0
TraceDll = /usr/odbc/lib/odbctrac.so
TraceFile = /home/xxxx/odbctrace.log
TraceAutoStop = 0
[ODBC Data Sources]
default = tdata.so
testdsn = tdata.so
[default]
Driver = /usr/odbc/drivers/tdata.so
Description = Default DSN is Teradata 5100
DBCName = **ip_addr**
LastUser = DLPStats
Username = xxxx
Password = xxxx
Database = MSS_TEMP
DefaultDatabase = MSS_TEMP
[tdsn]
Driver=/usr/odbc/drivers/tdata.so
Description=Teradata running Teradata V1R5.2
DBCName=**ip_addr**
LastUser=
Username=xxxx
Password=xxxx
Database=
DefaultDatabase=
错误:
DBI connect('tdsn','xxxx',...) failed: (no error string) at ./teradata.pl line 13
odbcinst.ini
[ODBC DRIVERS]
Teradata=Installed
[Teradata]
Driver=/usr/odbc/drivers/tdata.so
APILevel=CORE
ConnectFunctions=YYY
DriverODBCVer=3.51
SQLLevel=1
您需要下载并安装Teradata DBD模块。
$ip不能是ip地址。它需要是ODBC驱动程序管理器已知的ODBC数据源的名称。我们需要了解您的司机经理以提供进一步帮助。假设它是unixODBC,您将有一个需要在其中命名teradata驱动程序的odbcinst.ini文件,其中有一行指向驱动程序共享对象。然后在odbc.ini文件中创建一个数据源。
我很确定你已经找到了答案,但我无论如何都会发布它,以防其他人需要:
odbcinst.ini:
[Teradata Database ODBC Driver 16.20]
Description=Teradata Database ODBC Driver 16.20
Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so
# Note: Currently, Data Direct Driver Manager does not support Connection Pooling feature.
CPTimeout=60
odbc.ini:
[ODBC Data Sources]
16.10=Teradata Database ODBC Driver 16.20
15.10=Teradata Database ODBC Driver 16.20
13.00=Teradata Database ODBC Driver 16.20
13.10=Teradata Database ODBC Driver 16.20
14.00=Teradata Database ODBC Driver 16.20
请注意,数据源的名称可以是任何内容,在本例中我选择了版本。
Perl代码:
use DBD::ODBC;
my $conn = DBI->connect("DBI:ODBC:14.00",$username,$password);
#note how I'm connecting to the data source 14.00
my $create_user = $conn->prepare("CREATE USER $db_user from $username as perm = $perm,
password = XXXXXX,
spool = $spool,
NO fallback protection,
default database = $db_user,
NO after journal");
my $status = $create_user->execute();
$conn->disconnect();