如何连接到从UNIX Oracle数据库(how to connect to an oracle d

2019-10-22 08:44发布

我想从我的UNIX机器连接到Oracle数据库。 我一般是新来的剧本创作。 我知道如何浏览圆UNIX和已经编写Basic脚本(读/显示),并与bash命令执行。 此外,我知道如何查看UNIX中的变量(用户和系统)。 你能告诉我什么,我需要做的连接到Oracle数据库? 我用sqlplus命令? 是否有任何变量我必须在那之前设置?

Answer 1:

你能告诉我什么,我需要做的连接到Oracle数据库? 我用sqlplus命令?

嗯,是的,当然,你需要使用SQL * Plus。 然而,在这之前,你需要确保的几件事情:

  1. 出口ORACLE_HOME变量

例如,

export ORACLE_HOME=/u01/app/oracle/product/11.2.0
  1. 出口PATH变量

例如,

export PATH=$PATH:$ORACLE_HOME/bin
  1. 出口SID

例如,

export ORACLE_SID="your database service name"
  1. 确保您已在tnsnames.ora正确配置
  2. 请确保您有listener和运行,监听到正确的端口。

你应该能够连接到数据库:

sqlplus username/password@sid


Answer 2:

设置ORACLE_HOME和ORACLE_SID环境变量。 然后使用sqlplus的用户名@ ORACLE_SID



Answer 3:

请确保您已远销所有必要的Oracle变量在您的UNIX用户路径如下环境:

ORACLE_BASE=/home/oracle/app; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1/; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$HOME/bin:$PATH; export PATH

并确保tnsnames.ora文件配置正确,听者应达和下面运行。

[oracle@OLE1 admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ole1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

[oracle@OLE1 ~]$ tnsping orcl
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 12-JUL-2017 23:12:35
Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:
/home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ole1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (20 msec)
[oracle@OLE1 ~]$ 

[oracle@OLE1 ~]$ cat /etc/hosts
127.0.0.1   localhost
::1         localhost
192.168.244.128 ole1
[oracle@OLE1 ~]$ 

现在你已经通过多种方式从UNIX命令提示符下连接数据库。

甲骨文@ OLE 1〜] $ sqlplus的斯科特/老虎

甲骨文@ OLE 1〜] $ sqlplus的斯科特/老虎@ ORCL

甲骨文@ OLE 1〜] $ sqlplus中scott/tiger@192.168.244.128:1521 / ORCL

甲骨文@ OLE 1〜] $ sqlplus的斯科特/老虎@ // 192.168.244.128:1521/orcl

[预言@ OLE1〜] $ SQLPLUS“斯科特/老虎@(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = OLE1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ORCL))) “

[oracle@OLE1 ~]$ sqlplus scott/tiger
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 12 23:29:30 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@OLE1 ~]$ sqlplus scott/tiger@orcl
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 12 23:30:00 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected
[oracle@OLE1 ~]$ 

[oracle@OLE1 ~]$ sqlplus scott/tiger@192.168.244.128:1521/orcl
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 12 23:30:00 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected
[oracle@OLE1 ~]$ 


[oracle@OLE1 ~]$ sqlplus scott/tiger@//192.168.244.128:1521/orcl
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 12 23:30:00 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected
[oracle@OLE1 ~]$ 
[oracle@OLE1 ~]$ sqlplus "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ole1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jul 13 12:30:23 2017

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 
SQL> show user
USER is "SCOTT"
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@OLE1 ~]$


文章来源: how to connect to an oracle database from unix