一、如何在ubuntu18.04下连接oracle数据库
1、打开oracle官方网站,下载文件
- oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
- oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
- oracle-instantclient19.5-sqlplus-19.5.0.0.0-1.x86_64.rpm
2、安装以上三个文件
(1)安装alien
- sudo apt-get install alien
(2)安装三个rpm包
- sudo alien -i oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
- sudo alien -i oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
- sudo alien -i oracle-instantclient19.5-sqlplus-19.5.0.0.0-1.x86_64.rpm
3、配置环境变量
(1)打开/etc/profile
在最后面添加环境变量
export ORACLE_HOME="/usr/lib/oracle/19.5/client64"
export TNS_ADMIN="$ORACLE_HOME/network/admin"
export LD_LIBRARY_PATH="$ORACLE_HOME/lib"
export PATH="$ORACLE_HOME/bin:$PATH"
(2)生效环境变量
4、配置tnsnames.ora文件
- cd /usr/lib/oracle/19.5/client64
- mkdir -p network/admin
- vim tnsnames.ora
配置tnsnames.ora文件,DBNAME就是随便起的名字,HOST是数据库的ip地址。其他复制即可。
DBNAME =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ems)
)
)
5、测试连接
|