table of Contents
1. InstantClient to download Oracle data
Two, install the instantClient of Oracle data and configure environment variables
In this document, we are using Oracle 11g database, so the installed version of cx-Oracle is 5.3
1. InstantClient to download Oracle data
Download link https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
下载 oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Download oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
Two, install the instantClient of Oracle data and configure environment variables
For Linux systems that use rpm packages as carrier software, such as redhat/centos, you can directly use the command: rpm –ivh xxx.rpm to install the rpm package by default, or you can specify the installation to a certain directory. Specify the installation directory for the package: add the -relocate parameter.
For example, install the xxx.rpm package, install it with the relocate parameter, and install it to the /opt/temp directory:
rpm -ivh --relocate /=/opt/temp xxx.rpm;
Install with prefix:
rpm -ivh --prefix= /opt/temp xxx.rpm
1.安装oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm using rpm
rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
There is a dependency problem:
Install libaio
yum install libaio
Install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm again using rpm
2. Install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
After the installation is successful, you can see the Oracle folder in the /usr/lib/ directory
3. Configure environment variables
Use vi to open the profile and add the following environment variables at the end of the file:
vi /etc/profile
export ORACLE_HOME=/usr/lib/oracle/11.2/client64/
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
Run the command to make the changes take effect immediately
source /etc/profile
Enter echo $ORACLE_HOME and output /usr/lib/oracle/11.2/client64/ to show that the Oracle environment variables are configured
Three, install cx-Oracle
pip install cx-Oracle==5.3
If there is no error, then the installation is complete and you can write a python program to test it.