欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Oracle數據庫Python連接方法

系統(tǒng) 2276 0

Connecting Python to Oracle Cloud Database

There are three flavors of Oracle Databases hosted on Oracle Cloud Infrastructure:

  1. Bare Mental, VM, and Exadata
  2. Autonomous Data Warehouse (ADWC)
  3. Autonomous Transaction Processing

Here we are refering "Oracle database" to Autonomous Data Warehouse, while all three should be similar in connectivity interface as they are Oracle-like.

For those of you who don't have an Oracle cloud account, be reminded that you can apply for a free-trial account with 30-day trial period and $3000 HKD usable balance.

Before you begin

Before we discuss how to access Oracle database from Python, you should have already provisioned an Autonomous Data Warehouse instance. Refer to official doc for how to provision. Basically, you need to first construct a VCN (Virtual Cloud Network) under Networking tag, as later you'll be prompted to bind your ADWC to one of the VCNs. In the startup dialog of provisioning the ADWC, choose storage and other parameters, set up your ADMIN account, etc.

Wait for the ADWC instance (in my case, it is called demo ) to turn from Provising is in Available state, enter the details page, and enter DB Connection page. From the Download button, download the client credentials (a.k.a. your wallet**). The wallet is very important and you will need it to make client connections via any method (SQLDeveloper, Language driver, etc).

Install Oracle Client and Python driver

To make connections to Oracle database, you need an Oracle client. Oracle client can a full one that takes a lot of space, or a light-weight one, Instant Client . Because a full client is not available on macOS, I opt for the Instant Client. Download the zip file of proper DB version and OS, and place it in your workspace

          
            cd ~/Downloads
unzip instantclient-basic-macos.x64-18.1.0.0.0.zip
cd instantclient_18_1
          
        

We will also need the Python driver cx_Oracle . I recommend using PyPI

          
            python -m pip install cx_Oracle --upgrade
          
        

instantclient_18_1 directory has the dynamic libraries required by cx_Oracle , they must be on the Library Search Path in macOS dynamic linking process, available for the dlpen call from cx_Oracle .

…, the dynamic loader searches for the library in several locations until it finds it, in the following order:

  1. $LD_LIBRARY_PATH
  2. $DYLD_LIBRARY_PATH
  3. The process’s working directory
  4. $DYLD_FALLBACK_LIBRARY_PATH

Hence, we have several options, such as work in the instantclient_18_1 directory. Or, create a symbol link in DYLD_FALLBACK_LIBRARY_PATH which has a default value $HOME/lib;/usr/local/lib;/usr/lib . The second method is more flexible since we don't have to stay in the client directory forever

          
            ln -s ~/Downloads/instantclient_18_1/libclntsh.dylib ~/lib/
          
        

Configure Oracle database TNS

TNS stands for Transparent Network Substrate , an Oracle computer-networking technology mainly designed for connection to Oracle databases. We need to tell the Instant Client the TNS information of the database we would like to access.

          
            cd ~/Downloads/instantclient_18_1/network/admin
          
        

If there is not network/admin inside, mkdir the subdirectories.

Unzip the wallet files to network/admin

          
            unzip ~/Downloads/Wallet_demo.zip .
ls
# README           ewallet.p12      ojdbc.properties tnsnames.ora
# cwallet.sso      keystore.jks     sqlnet.ora       truststore.jks
          
        

There are a bunch of files in the wallet, but only three of them is required to make the connection (though you can always put all files inside network/admin ). tnsnames.ora defines the namespace of where to find the databases (host, portnumber, service name) when cx_Oracle is asked to make a connection.

          
            cat tnsnames.ora
          
        
          
            demo_high = (description= (address=(protocol=tcps)(port=1522)(host=adb.ap-tokyo-1.oraclecloud.com))(connect_data=(service_name=lsd2p1z0t6mcrz2_demo_high.adwc.oraclecloud.com))(security=(ssl_server_cert_dn=
        "CN=adb.ap-tokyo-1.oraclecloud.com,OU=Oracle ADB TOKYO,O=Oracle Corporation,L=Redwood City,ST=California,C=US"))   )
# ...
          
        

There are other TNS entry points, like demo_medium and demo_low , they refer to different volumes of data transfer between the client and the database.

Get to the Python part

We are all set, lets create a python script with the following content:

          
            import cx_Oracle

connection = cx_Oracle.connect('
            
              ', '
              
                ', 'demo_high')
print('Database version:', connection.version)
connection.close()
              
            
          
        

If the script terminates with any error, you will see output

          
            (base) ?  Desktop python connection.py
Database version: 18.4.0.0.0
          
        

Then we successfully connect to the database.

Note: the third parameter of cx_Oracle.connect should one of the names defined in tnsnames.ora like demo_high , demo_HIGH (TNS name is case-insensitive), NOT the long connection string (something starting with adb.ap-tokyo-1.oraclecloud.com ). If you mistakenly use the connection string as the third parameter, you are likely to end up with error TNS: connection closed .


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色综合久久精品中文字幕首页 | 国产99久久精品一区二区 | 国产成人综合日韩精品婷婷九月 | 成人羞羞网站 | 波多野一区二区 | 关键词 | 国产一精品一av一免费爽爽 | 亚洲精品国偷拍自产在线观看 | 奇米777四色影视在线看 | 久草草视频在线观看免费高清 | 国内成人自拍视频 | 夜夜爽夜夜叫夜夜高潮漏水 | 狠狠色噜噜综合社区 | 台湾av在线| 唐人社电亚洲一区二区三区 | 国产精品久久久久aaaa九色 | 国产二区三区视频 | 96精品免费视频大全 | 欧美三级欧美一级 | 欧美性高清bbbbbbxxxxx | 综合色久| 欧洲色阁中文字幕 | 亚洲综合无码一区二区 | 韩国精品一区二区 | 激情成人综合网 | 青青草无限次破解版污 | 日韩欧美视频在线一区二区 | 日本一区二区精品视频 | 日韩在线视频一区 | 欧美1区 | 成人午夜视频在线观看 | 91高清视频在线观看 | 黑粗硬大欧美 | 日本久久久久中文字幕 | 老美AA片| 国产在线看一区 | 国产日韩欧美一区 | 激情视频区 | 欧美变态口味重另类日韩毛片 | 久久久精品一区二区三区 | 201天天爱天天做 |