Python Source Installation Cx_oracle

Source: Internet
Author: User

There's a data sheet on the line for one months. No data, no monitoring, Boss let me do a monitor, let Python write script to monitor the Oracle data is normal.

First, the package involved

1, Cx_oracle

: Http://sourceforge.net/projects/cx-oracle/files/?source=navbar

I downloaded the latest version of the cx_oracle-5.1.2.tar.gz.

2, Oracle_client

Use Cx_oracle to install the oracle_client side, or you have already installed the Oracle database

: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Oracle-instantclient11.2-basic-11.2.0.4.0-1. X86_64.rpmoracle-instantclient11.2-jdbc-11.2.0.4.0-1. X86_64.rpmoracle-instantclient11.2-sqlplus-11.2.0.4.0-1. X86_64.rpmoracle-instantclient11.2-devel-11.2.0.4.0-1. X86_64.rpmoracle-instantclient11.2-odbc-11.2.0.4.0-1. X86_64.rpmoracle-instantclient11.2-tools-11.2.0.4.0-1. x86_64.rpm

Once the packages have been downloaded, we start to install them.

Second, the source code installation

1, oracle_client End installation:

# RPM-IVH oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm  oracle-instantclient11.2-jdbc-11.2.0.4.0-1.x86_64.rpm  oracle-instantclient11.2-sqlplus-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-odbc-11.2.0.4.0-1.x86_64.rpm  oracle-instantclient11.2-tools-11.2.0.4.0-1.x86_64. RPM#  echo/usr/lib/oracle/11.2/client64/lib/>>/etc/ld.so.conf#  Ldconfig

If you do not configure Ldconfig, the following error is reported when you run Cx_oracle:

or directory

2, set the corresponding user's environment variables:

Here you need to explain, which account you use to install cx_oracle you need to configure which account environment variables, the following root account as an example;

If you do not configure an environment variable, or if the environment variable is not configured correctly, various errors are reported when installing cx_oracle, such as:

Oci.h:no such fileorDirectory#VI ~/.BASHRCExport tns_admin="/usr/lib/oracle"Export Oracle_home="/usr/lib/oracle/11.2/client64"Export Ld_library_path="${ld_library_path}:${oracle_home}/lib"Export PATH="${path}:${oracle_home}"#Source ~/.BASHRC

3. Source code Installation

# TAR-ZXVF cx_oracle-5.1.2.tar.gz # CD cx_oracle-5.1.2 # python setup.py Install

4, after the successful installation of the corresponding inspection

[[email protected] Scripts]#pythonPython 3.3.0 (Default, Sep 14 2017, 14:53:20) [GCC4.8.5 20150623 (Red Hat 4.8.5-11)] on Linuxtype" Help","Copyright","credits" or "License"  forMore information.>>>Importcx_oracle>>>
Third, the script instance:
#!/usr/bin/python#-*-coding:utf-8-*-Importcx_oracle as DBImportosos.environ['Nls_lang'] ='simplified Chinese_china. UTF8'defqueryoracle (SQL): Username="Us_order"      #User namepasswd ="******"          #User PasswordHost ="192.168.1.203"     #Server IPPort ="1521"              #Oracle PortSid ="ORCL"               #Oracle'sDSN =DB.MAKEDSN (host, port, sid) Con=db.connect (username, passwd, DSN) cur=con.cursor () cur.execute (SQL) result=Cur.fetchall () cur.close () Con.close ( )returnresultif __name__=="__main__": SQL="Select Sysdate from dual"    #the SQL that needs to be executedresult =queryoracle (SQL)Print(Result)

Execution Result:

[[email protected] Scripts] # ./check_oracle_tables.py

Python Source Installation Cx_oracle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.