- Install cx_oracle
sudo python -m pip3 install cx_Oracle --upgrade
or
sudo pip3 install cx_Oracle --pre
- Download the instant client package:
-
Unzip and place in the oracle directory
mkdir -p /opt/oracle unzip instantclient-basic-macos.x64-12.2.0.1.0.zip
-
Create a soft link so that the required library can be found when the program is started
ln -s /opt/oracle/instantclient_12_2/libclntsh.dylib ~/lib/
If there is no
lib
file, create a newmkdir ~/lib
-
Copy the OCI library
cp /opt/oracle/instantclient_12_2/{libclntsh.dylib.12.1,libclntshcore.dylib.12.1,libons.dylib,libnnz12.dylib,libociei.dylib} ~/lib/
-
Connect to the database test code:
import cx_Oracle #引用模块cx_Oracle conn=cx_Oracle.connect('trump/[email protected]:1521/EE.oracle.docker') #连接数据库 c=conn.cursor() #获取cursor x=c.execute('select * from users') #使用cursor进行各种操作 print(x.fetchall()) c.close() #关闭cursor conn.close()
Each of EE.oracle.docker
them has a different installation and configuration, some are database instance names, some are global database names, I use the latter, see for details
result:
```
[(283, 'qxj', '123456'), (1, 'quanxj', '654321')]
```
success