zoukankan      html  css  js  c++  java
  • 在CentOs6.x 安装Cx_oracle5.x

    Setting up anything Oracle related is a huge pain. After hunting the web for info with minimal success, I have decided to create a small tutorial to walk through setting up cx_Oracle to connect to Oracle installations.

    Prerequisites

    If you do not have a Oracle.com account, you will unfortunately need to create one to be able to download anything. Once you have your account head to the OS Selection page and select the appropriate OS, in my case this will be Linux / AMD64. On the subsequent page you must download the basiclite package as well as the devel package. I chose the RPM files as I am running CentOS 6.x. If you want non-English application support you probably want to install the basic version instead of the basiclite, it has multilingual support built in. You may optionally want to install the sqlplus package to help with debugging and connection issues.

    Oracle Library Installation

    I downloaded the RPM files so ill use the rpm command to install the packages as follows

    1
    2
    3
    4
    5
    6
    7
    [root@devel ~] # cd oracle_files
    [root@devel oracle_files]# rpm -ivh 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
    Preparing... ########################################### [100%]
    1:oracle-instantclient11.########################################### [ 33%]
    2:oracle-instantclient11.########################################### [ 67%]
    3:oracle-instantclient11.########################################### [100%]
    [root@devel oracle_files]#

    This will install the client under /usr/lib/oracle/11.2/client64/ by default under CentOS. Now this path is not listed under the shared library path by default (why doesn't this get setup by default?), so we must add it. Create the following file: /etc/ld.so.conf.d/oracle.conf with the following contents, adjusted accordingly to your installation:

    1 /usr/lib/oracle/11.2/client64/lib

    With that in place we can now enable the shared library path system wide as follows:

    1 [root@devel ~]# ldconfig

    To verify the library path installation you can try and run the sqlplus client. If it fails to start then you have a problem and should look into any mistakes that may have occurred during the installation process.

    1
    2
    3
    4
    5
    6
    [root@devel ~]# PATH=$PATH:/usr/lib/oracle/11.2/client64/bin # place in ~/.bashrc for a permanent setup
    [root@devel ~]# sqlplus
    SQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 16:57:40 2012
    Copyright (c) 1982, 2011, Oracle. All rights reserved.

    Python Library Installation

    With the oracle libraries installed we can now begin installing the python connector cx_Oracle. I will be building a rpm file from the source rpm. If you are not using CentOS, or don't want to build a rpm for whatever reason, then go ahead and grab the source tarball instead.

    Building and installing from source rpm:

    1
    2
    3
    4
    5
    6
    7
    8
    [root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.src.rpm
    1:cx_Oracle ########################################### [100%]
    [root@devel ~]# cd ~/rpmbuild/SPECS
    [root@devel ~]# yum install rpm-build
    [root@devel ~]# ORACLE_HOME=/usr/lib/oracle/11.2/client64/ rpmbuild -ba cx_Oracle.spec
    [root@devel ~]# cd ../RPMS/x86_64
    [root@devel ~]# rpm -ivh cx_Oracle-5.1.1-1.x86_64.rpm
    Preparing... ########################################### [100%]
    1:cx_Oracle ########################################### [100%]

    Or Building and installing from source tarball

    1
    2
    3
    4
    tar xvfz cx_Oracle.tar.gz
    cd cx_Oracle.tar.gz
    ORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py build
    ORACLE_HOME=/usr/lib/oracle/11.2/client64/ python setup.py install

    Verification

    To easily test if the installation has succeded run the following 1 liner, if no errors occur then your installation went OK.

    1 [root@devel x86_64]# python -c 'import cx_Oracle'
  • 相关阅读:
    Windows常用内容渗透命令
    字符串编码小记
    卡巴斯基命令解析
    聚合与继承
    Maven与Eclipse整合
    maven系列三:Maven核心概念
    使用Maven构建项目
    Maven项目构建过程练习
    maven系列二:Maven入门
    使用Maven构建多模块项目
  • 原文地址:https://www.cnblogs.com/noobkey/p/3637777.html
Copyright © 2011-2022 走看看