1. <var id="fe6gj"></var>

    <rp id="fe6gj"><nav id="fe6gj"></nav></rp>

    <noframes id="fe6gj"><cite id="fe6gj"></cite>

    <ins id="fe6gj"><button id="fe6gj"><p id="fe6gj"></p></button></ins>
    1. <tt id="fe6gj"><i id="fe6gj"><sub id="fe6gj"></sub></i></tt>
        始創于2000年 股票代碼:831685
        咨詢熱線:0371-60135900 注冊有禮 登錄
        • 掛牌上市企業
        • 60秒人工響應
        • 99.99%連通率
        • 7*24h人工
        • 故障100倍補償
        您的位置: 網站首頁 > 幫助中心>文章內容

        在Ubuntu下安裝Oracle Instant Client

        發布時間:  2012/9/17 16:43:52

        最近需要寫一個數據遷移腳本,將單一Oracle中的數據遷移到MySQL Sharding集群,剛好最近在學習python,就用它來練手。
        很快搞定了MySQL,只需要安裝一個MySQLdb的python模塊就可以了。但是對于Oracle客戶端,不只需要安裝相應的python模塊(這里我用了Oracle官方的python模塊——cx_Oracle),還需要安裝Oracle Client,一般選擇Instant Client就足夠了,還需要配置tnsnames.ora(當然也可以簡單的通過host:port/schema訪問)。 -
         


        下面是具體步驟。

        首先確定版本。因為我們的Oracle數據是在是有點老,所以我選擇了一個比較老的版本——Oracle Instant Client 10.2.0.4。一般從官方網站下載就可以了。下載地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html。這里要嚴重BS Oracle,居然要先注冊才能下載,這也算了,關鍵是注冊的時候,密碼居然要求有數字有字母,字母還要有大小寫,還必須至少8位。逼迫我搞了一個比我銀行密碼還要安全的密碼(好吧,現在我已經忘記我填了什么了。。)。下載的時候要特別注意,一定要下載rpm包,zip不知道是什么。下basic就可以了。
        forrest@Ubuntu:~/Sources$ wget http://download.Oracle.com/otn/linux/instantclient/10204/oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
        由于是rpm包,在Ubuntu下先將其轉成deb包:
        forrest@Ubuntu:~/Sources$ sudo alien Oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
        得到Oracle-instantclient-basic_10.2.0.4-2_amd64.deb。
        可以安裝了,
        forrest@Ubuntu:~/Sources$ sudo dpkg -i Oracle-instantclient-basic_10.2.0.4-2_amd64.deb
        這樣會安裝在默認的目錄下——/usr/lib/Oracle/10.2.0.4/client64/
        forrest@Ubuntu:/usr/lib/Oracle/10.2.0.4/client64$ ls
        bin  lib 


        安裝完成之后,還需要暴露一些環境變量,否則會報錯:
         * import cx_Oracle gave ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory until I set LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/
         * conn = cx_Oracle.Connection('scott/tiger@xe') gave RuntimeError: Unable to acquire Oracle environment handle until I set ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server


        forrest@Ubuntu:~/Sources$ sudo vim ~/.profile
        在最后添加如下語句:
        export Oracle_HOME=/usr/lib/oracle/10.2.0.4/client64
        export PATH=$PATH:$Oracle_HOME/bin
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Oracle_HOME/lib
        export TNS_ADMIN=$Oracle_HOME/network/admin


        注意到TNS_ADMIN所在目錄其實并不存在,是要自己創建的(這個也很惡心,我一開始以為還要安裝什么東東。。)
        $ sudo mkdir -p $Oracle_HOME/network/admin
        $ sudo cp tnsnames.ora $Oracle_HOME/network/admin

        如果你有安裝sqlplus,此時就可以用它來測試安裝是否正確了:
        $ sqlplus 'username/password@SID'

        不過linux下的sqlplus太爛,我沒打算安裝,所以留著吧,接下去安裝python模塊——cx_Oracle——參考Install cx_Oracle in Ubuntu(http://leojay.blog.163.com/blog/static/1739841912009101165546640/
        到SourceForge搜索cx_Oracle,根據我的python版本和要操作的數據庫版本,選擇了cx_Oracle-5.1-10g-py26-1.x86_64.rpm這個版本,只能說我相信高版本是向后兼容的。先試一下吧,呵呵。
        下完之后解壓,將cx_Oracle.so放在dist-packages下:
        $ sudo cp cx_Oracle.so /usr/local/lib/python2.6/dist-packages/
        這樣就OK了。
        寫個簡單的測試程序測試一下吧:
        #!bin/python
        import cx_Oracle

        conn = cx_Oracle.connect('user/passwd@sid')

        cursor = conn.cursor()
        cursor.execute("SELECT * from product_detail where product_id = 232896483")
        row = cursor.fetchone()
        print "result: ", row

        cursor.close()
        conn.close()

        如果沒有問題應該就可以看到結果了。這時候一般會遇到這樣的問題:
        forrest@Ubuntu:~/work/data-migration$ python Oracledb.py
        Traceback (most recent call last):
          File "Oracledb.py", line 5, in <module>
            conn = cx_Oracle.connect(''user/passwd@sid')
        cx_Oracle.DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
        查看一下你的/usr/lib/Oracle/10.2.0.4/client64/network/admin/tnsnames.ora配置文件,確保sid是配置正確的。
        或者直接使用host:port/schema方式:
        conn = cx_Oracle.connect('user/passwd@host:port/schema')


        如果有其他問題,可以在/usr/lib/Oracle/10.2.0.4/client64/network/admin下添加一個sqlnet.ora文件,以trace方式運行:
        If for some reason you have some trouble connecting, you can create a sqlnet.ora file under $Oracle_HOME with some tracing options.
        $ sudo vi $Oracle_HOME/network/admin/sqlnet.ora
        TRACE_DIRECTORY_CLIENT=/tmp
        TRACE_LEVEL_CLIENT=SUPPORT


        The next time the Oracle Instant Client is used, it will create a detailed log file under /tmp like the following: cli_1968.trc. Make sure to turn this option off when you are done as the logfile can get quite large!

        PS:目前看來cx_Oracle還是有向下兼容的。希望如此,搞個環境比寫個程序麻煩多了


        本文出自:億恩科技【www.endtimedelusion.com】

        服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]

      1. 您可能在找
      2. 億恩北京公司:
      3. 經營性ICP/ISP證:京B2-20150015
      4. 億恩鄭州公司:
      5. 經營性ICP/ISP/IDC證:豫B1.B2-20060070
      6. 億恩南昌公司:
      7. 經營性ICP/ISP證:贛B2-20080012
      8. 服務器/云主機 24小時售后服務電話:0371-60135900
      9. 虛擬主機/智能建站 24小時售后服務電話:0371-60135900
      10. 專注服務器托管17年
        掃掃關注-微信公眾號
        0371-60135900
        Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權所有  地址:鄭州市高新區翠竹街1號總部企業基地億恩大廈  法律顧問:河南亞太人律師事務所郝建鋒、杜慧月律師   京公網安備41019702002023號
          0
         
         
         
         

        0371-60135900
        7*24小時客服服務熱線

         
         
        av不卡不卡在线观看_最近2018年中文字幕_亚洲欧美一区二区三区_一级A爱做片免费观看国产_日韩在线中文天天更新_伊人中文无码在线