欢迎投稿

今日深度:

python处理teradata数据库_Python脚本连接Teradata数据库,以下操作为Linux

python处理teradata数据库_Python脚本连接Teradata数据库,以下操作为Linux


Connect Teradata from

python

Base

on Linux Ubuntu with python2.7

参考网络搜索结果,具体出处不记得了,结合自身实践总结。以下操作为Linux环境,其他环境请自行调整。(中英文结合是因为这个总结最初也是受惠于歪果仁的分享)

1, Install python package

#依赖两个包

apt-get install python-pyodbc

apt-get install odbcinst

2, Download teradata dirver for

linux  #需要下载和安装Teradata客户端驱动

http://downloads.teradata.com/download/files/7455/188352/0/tdodbc__linux_indep.15.00.00.03-1.tar.gz

3, Install the teradata client and

driver by root on linux

install alien on server if not

installed

apt-get install alien

Unzip and install the drivers:

alien

tdicu-15.00.00.00-1.noarch.rpm

dpkg -i

tdicu_15.00.00.00-2_all.deb

alien

tdodbc-15.00.00.03-1.noarch.rpm

dpkg -i

tdodbc_15.00.00.03-2_all.deb

alien

TeraGSS_linux_x64-15.00.00.07-1.noarch.rpm

dpkg -i

teragss-linux-x64_15.00.00.07-2_all.deb

4, Add the teradata files to

ldconfig, by creating a new file,

/etc/ld.so.conf.d/Zteradata.conf with the contents:

/opt/teradata/client/15.00/odbc_64/lib

/opt/teradata/client/15.00/tdicu/lib64

/opt/teradata/teragss/linux-x8664/15.00.00.07/lib

5,Refresh the cache to include

these new lib directories:

ldconfig -v

6, Redirect default drivers to

teardata files. #在默认路径下建立软链接指向teradata驱动文件

cd /usr/lib/x86_64-linux-gnu

mv libodbc.so.1.0.0

Xlibodbc.so.1.0.0

ln -s

/opt/teradata/client/15.00/odbc_64/lib/libodbc.so

libodbc.so.1.0.0

mv libodbcinst.so.1.0.0

Xlibodbcinst.so.1.0.0

ln -s

/opt/teradata/client/15.00/odbc_64/lib/libodbcinst.so

libodbcinst.so.1.0.0

7, config for teragss

#配置teradata客户端组件

mkdir /usr/teragss/site

cp -R

/opt/teradata/teragss/linux-x8664/15.00.00.07/etc/*

/usr/teragss/site

mkdir /usr/teragss/linux-x8664

mkdir

/usr/teragss/linux-x8664/client

cd

/usr/teragss/linux-x8664/client

ln -s

/opt/teradata/teragss/linux-x8664/15.00.00.07/lib lib

cd

/opt/teradata/teragss/linux-x8664/15.00.00.07/bin

./run_tdgssconfig

8, modify odbc config file for

oracle user #将默认的两个配置文件复制到当前用户主目录下,并修改配置路径

cp

/opt/teradata/client/15.00/odbc_64/odbc.ini ~/.odbc.ini

cp

/opt/teradata/client/15.00/odbc_64/odbcinst.ini

~/.odbcinst.ini

Edit them to replace all

“TDODBC_INSTALL_DIR” with “/opt/teradata/client/15.00/odbc_64” and

replace “TDODBC_LIB_DIR” with “lib”

9,Add the data source to the ODBC

configuration file ~/.odbc.ini #在配置文件中增加data source信息

[ODBC Data Sources]

test_teradata=tdata.so

#其中test_teradata为自定义数据源名称

[test_teradata]

Driver=/opt/teradata/client/15.00/odbc_64/lib/tdata.so

Description=

DBCName=  #

此处为你要连接的teradata服务器名

LastUser=

Username= # 此处为连接的用户名

Password= # 此处为密码

Database=

DefaultDatabase=

#此处为默认连接服务器上的数据库

10, Edit user profile, add below

into ~/.profile to set environment #设置用户的环境变量

ODBCINI=$HOME/.odbc.ini

LD_LIBRARY_PATH=/opt/teradata/teragss/linux-x8664/15.00.00.07/lib:$LD_LIBRARY_PATH

export ODBCINI LD_LIBRARY_PATH

======================== 低调分割线

===========================

以上配置完成。

以下为python脚本中两种方式连接示例:

import pyodbc

pyodbc.pooling = False

# 1,直接连接 connect directly,here

{Teradata} is keyword, not variable。

conn=pyodbc.connect('DRIVER={Teradata};DBCNAME=db_server_name;UID=;PWD=;QUIETMODE=YES;',

ANSI=True, autocommit=True)

# 2,引用配置的数据源 connect

by data source name

conn=pyodbc.connect('DSN=test_teradata;QUIETMODE=YES;',

ANSI=True, autocommit=True)

测试连接不报错,那么恭喜你!否则回头检查哪个步骤手抖输入错误,如果还不行,自检人品。。。

www.htsjk.Com true http://www.htsjk.com/teradata/46053.html NewsArticle python处理teradata数据库_Python脚本连接Teradata数据库,以下操作为Linux Connect Teradata from python Base on Linux Ubuntu with python2.7 参考网络搜索结果具体出处不记得了结合自身实践总结。以下操作...
评论暂时关闭