Linux安装oracle客户端连接远端数据库
方法一(不需要tnsnames.ora):
1、安装软件(https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html) #rmp -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm #rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm #rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm 2检查 # rpm -qa|grep -i oracle oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64 oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64 oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64 3环境变量 [root@redaht69 tmp]# tail -15 /etc/profile #oracle_client11 export ORACLE_HOME=/usr/lib/oracle/11.2/client64 #export TNS_ADMIN=$ORACLE_HOME/network/admin export NLS_LANG='simplified chinese_china'.ZHS16GBK export LD_LIBRARY_PATH=$ORACLE_HOME/lib export PATH=$ORACLE_HOME/bin:$PATH 5测试 #sqlplus system/123456@//192.168.1.200:1521/orcl # vi /tmp/tablespace.sh sqlplus -S /nolog <<eof conn system/[email protected]:1521/orcl set line 200; set feedback off; set pagesize 50000; col member for a45; select a.tablespace_name,a.summary,b.free,b.maxf "MAX_FREE_EXTENT",b.free_exts "FREE_EXTENTS", 100-b.free/a.summary*100 "USED%" from (select tablespace_name,sum(bytes/1024/1024) "SUMMARY" from dba_data_files group by tablespace_name) a, (select tablespace_name,sum(bytes/1024/1024) "FREE",max(bytes/1024/1024) "MAXF" ,count(*) free_exts from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name order by 6 desc; eof exit;
方法二(需要tnsnames.ora):
1、安装软件 #rmp -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm #rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm #rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm 2检查 # rpm -qa|grep -i oracle oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64 oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64 oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64 3环境变量 [root@redaht69 tmp]# tail -15 /etc/profile #oracle_client11 export ORACLE_HOME=/usr/lib/oracle/11.2/client64 #export TNS_ADMIN=$ORACLE_HOME/network/admin export NLS_LANG='simplified chinese_china'.ZHS16GBK export LD_LIBRARY_PATH=$ORACLE_HOME/lib export PATH=$ORACLE_HOME/bin:$PATH 4创建tnsnames.ora vi /usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.200)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL) ) ) 5测试 #sqlplus system/123456@orcl # vi /tmp/tablespace.sh sqlplus -S /nolog <<eof conn system/123456@orcl set line 200; set feedback off; set pagesize 50000; col member for a45; select a.tablespace_name,a.summary,b.free,b.maxf "MAX_FREE_EXTENT",b.free_exts "FREE_EXTENTS", 100-b.free/a.summary*100 "USED%" from (select tablespace_name,sum(bytes/1024/1024) "SUMMARY" from dba_data_files group by tablespace_name) a, (select tablespace_name,sum(bytes/1024/1024) "FREE",max(bytes/1024/1024) "MAXF" ,count(*) free_exts from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name order by 6 desc; eof exit;