python调用sqlserver依赖pymssql+freetds驱动,freetds依赖gcc
cpp-4.8.5-36.el7.x86_64.rpm
gcc-4.8.5-36.el7.x86_64.rpm
glibc-2.17-260.el7.x86_64.rpm
glibc-common-2.17-260.el7.x86_64.rpm
glibc-devel-2.17-260.el7.x86_64.rpm
glibc-headers-2.17-260.el7.x86_64.rpm
kernel-headers-3.10.0-957.el7.x86_64.rpm
libgcc-4.8.5-36.el7.x86_64.rpm
libgomp-4.8.5-36.el7.x86_64.rpm
libmpc-1.0.1-3.el7.x86_64.rpm
mpfr-3.1.1-4.el7.x86_64.rpm
依赖包下载地址:https://pkgs.org/
#查看glibc-2.17-260.el7.x86_64.rpm 及 glibc-common-2.17-260.el7.x86_64.rpm,是否已安装,避免安装冲突
rpm -qa | grep glibc;
---------------------------------------
> glibc-common-2.17-55.el7.x86_64
> glibc-2.17-55.el7.x86_64
---------------------------------------
#升级相关依赖包避免冲突
rpm -Uvh glibc-2.17-260.el7.x86_64.rpm glibc-common-2.17-260.el7.x86_64.rpm libgomp-4.8.5-36.el7.x86_64.rpm libgcc-4.8.5-36.el7.x86_64.rpm;
#安装剩下的依赖包
rpm -ivh gcc-4.8.5-36.el7.x86_64.rpm cpp-4.8.5-36.el7.x86_64.rpm glibc-devel-2.17-260.el7.x86_64.rpm glibc-headers-2.17-260.el7.x86_64.rpm kernel-headers-3.10.0-957.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm mpfr-3.1.1-4.el7.x86_64.rpm;
#查看gcc版本
gcc -v
----------------------------------------
>Using built-in specs.
>COLLECT_GCC=gcc
>COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
>Target: x86_64-redhat-linux
>Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
>Thread model: posix
>gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
----------------------------------------
#安装成功
官网下载页面:http://www.freetds.org/files/stable/
版本下载地址:http://www.freetds.org/files/stable/freetds-1.00.109.tar.gz
tar xvf freetds-1.00.109.tar.gz;
cd freetds-1.00.109;
#--with-unixodbc=/usr/local/unixODBC-2.3.7
./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib --enable-dbmfix --enable-shared --enable-static;
make;
make install;
#解释
-------------------------------------------
>--prefix设置FreeTDS的安装目录
>--with-tdsver设置TDS版本
>--enable-msdblib允许Microsoft数据库函数库
-------------------------------------------
#将tsql命令加入环境变量
-------------------------------------------
vim ~/.bashrc;
-------------------------------------------
>FREETDS_HOME=/usr/local/freetds
>export PATH=$FREETDS_HOME/bin:$PATH
-------------------------------------------
source ~/.bashrc;
-------------------------------------------
tsql -C; #查看版本信息
-------------------------------------------
>Compile-time settings (established with the "configure" script)
> Version: freetds v1.00.109
> freetds.conf directory: /usr/local/freetds/etc
> MS db-lib source compatibility: yes
> Sybase binary compatibility: no
> Thread safety: yes
> iconv library: yes
> TDS version: 7.4
> iODBC: no
> unixodbc: no
> SSPI "trusted" logins: no
> Kerberos: no
> OpenSSL: no
> GnuTLS: no
> MARS: no
-----------------------------------------------------------
#库文件加载
echo "/usr/local/freetds/lib" > /etc/ld.so.conf.d/freetds.conf;
ldconfig;
vim /usr/local/freetds/etc/freetds.conf;
------------------------------------
#sqlserver 2012配置
>[sql-server-2012]
> host = xxx.xxx.xxx
> port = 1433
> tds version = 7.4
#sqlserver 2005配置
>[2005SQL]
> host = xxx.xxx.xxx
> port = 1433
> tds version = 8.0
#sqlserver 2008配置
>[sql-server-2008]
> host = xxx.xxx.xxx
> port = 1433
> tds version = 8.0
> client chaeset = UTF-8
------------------------------------
#测试连接
tsql -S sql-server-2008 -U 用户名 -P 密码;
use test;#使用指定数据库
go;
扩展包下载地址:https://pypi.org/project
tar xvf setuptools-0.6c11.tar.gz;
tar xvf pip-18.1.tar.gz;
cd setuptools-0.6c11 && python setup.py install;
cd pip-18.1 && python setup.py install;
pip install pymssql-2.1.4-cp27-cp27mu-manylinux1_x86_64.whl;
python;
----------------------------------
>import pymssql
>
python调用oracle数据依赖于cx_Oracle+oracle-instantclient
下载地址:https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
根据oracle的版本下载对应的rpm包:
清单:
oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
#对所有用户生效(永久)
vim /etc/profile
source /etc/profile
#对单一用户生效(永久) 用户目录下文件/home/xxx/
vim ~/.bash_profile;
source ~/.bash_profile;
#执行允许export(对当前shell临时有效)
export ..........
#----------------------------------------------------------
vim ~/.bash_profile;
-----------------------------------------------------------
>export ORACLE_HOME=/usr/lib/oracle/11.2/client64
>export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
-----------------------------------------------------------
source ~/.bash_profile;
echo $ORACLE_HOME;#检查生效
#新建软连接
cd /usr/lib/oracle/11.2/client64/lib && ln –s libclntsh.so.11.1 libclntsh.so
下载地址:https://pypi.org/project/cx-Oracle/
pip install cx_Oracle-7.0.0-cp27-cp27mu-manylinux1_x86_64.whl;
python;
>import cx_Oracle
>cx_Oracle.SessionPool(user= 't', password= 't', dsn= '192.168.0.xxx:1521/orcl', min=1, max=10, increment=1)
>> :OK!
yum install -y gcc-c++ python-devel
;
离线安装请自行查询
tar xvf unixODBC-2.3.7.tar.gz;
cd unixODBC-2.3.7/
./configure --prefix=/usr/local/unixODBC-2.3.7 --includedir=/usr/include --libdir=/usr/local/lib -bindir=/usr/bin --sysconfdir=/usr/local/etc;
make && make install
yum install -y unixODBC unixODBC-devel
uname -r
rpm -ivh unixODBC-devel-2.3.1-11.el7.x86_64.rpm
isql --version
isql -j
pip install pyodbc
或者
pip install pyodbc-4.0.28.tar.gz
备份
[root@dongfangyiyuan ~]# cat /usr/local/etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/local/freetds/lib/libtdsodbc.so
Setup = /usr/local/freetds/lib/libtdsodbc.so
vim /usr/local/etc/odbcinst.ini;
-------------------------------------------------
[FreeTDS] # unixodbc驱动名称
Description=ODBC of FreeTDS for MS SQL 2008 # 简介
Driver=/usr/local/freetds/lib/libtdsodbc.so # 驱动所在位置
#################################################################
vim /usr/local/etc/odbc.ini;
---------------------------------------------------
[root@dongfangyiyuan ~]# cat /usr/local/etc/odbc.ini
[BYZY]
Driver = FreeTDS
Description = odbc for sybase
Server = 192.168.3.16
Port = 5000
TDS_Version = 5.0
[BYMZ]
Driver = FreeTDS
Description = odbc for sybase
Server = 192.168.3.15
Port = 5000
TDS_Version = 5.0
[NYZY]
Driver = FreeTDS
Description = odbc for sybase
Server = 172.31.10.202
Port = 5000
TDS_Version = 5.0
[NYMZ]
Driver = FreeTDS
Description = odbc for sybase
Server = 172.31.10.201
Port = 5000
TDS_Version = 5.0
[BSEMR]
Driver = FreeTDS
Description = odbc for sybase
Server = 172.31.10.87
Port = 5000
TDS_Version = 5.0
isql -v TEST2dsn ${user} ${password};