第一步:下载instantclient
instantclient-basic-linux.x64-12.1.0.2.0.zip //必须
instantclient-sqlplus-linux.x64-12.1.0.2.0.zip //必须
instantclient-odbc-linux.x64-12.1.0.2.0.zip//此处不需要,为unixODBC连接时,需要使用的包
将上面2个zip包解压到到任意位置,例如/opt/oracle/instantclient_12_1.
下面为oracle官方文档
3. Create the appropriate libclntsh.so and libocci.so links for the version of Instant Client. For example:
cd /opt/oracle/instantclient_12_1
ln -s libclntsh.so.12.1 libclntsh.so
ln -s libocci.so.12.1 libocci.so
4. Install the libaio package, for example on Oracle Linux, run this as the root user: //注意我并未安装libaio包
yum install libaio
On some Linux distributions the package is called libaio1.
第二步:
配置环境变量:
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_12_1:$PATHNLS_LANG=”AMERICAN_AMERICA.AL32UTF8″
在数据库中查询数据库服务名称
select value from v$parameter where name='service_names'
登录:sqlplus username/passwd@IP:port/servicename //特别注意port后为servicename,而不是instance name。
第三步:通过配置 tnsnames.ora访问oracle
配置环境变量
export TNS_ADMIN=/opt/oracle/instantclient_12_1
在TNS_ADMIN下建立tnsnames.ora文件
内容为:
oracledb = //登陆的SID (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.103.232)(PORT = 1521)) //IP地址和端口号 (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orc9i) //要链接数据库servicename ) )
登录sqlplus username/passwd@oracledb