Oracle通过sqlplus连接数据库的方式
通过sqlplus可以连接数据库根据用户权限进行数据或者设定操作,这篇文章介绍一下常用的连接方式。
环境准备
使用Oracle的精简版创建docker方式的demo环境,详细可参看:
- https://www.jb51.net/article/153533.htm
方式1(本机): / as sysdba
在oracle服务器,可以直接通过操作系统权限认证,使用sysdba方式登陆,前提是你可以登入服务器,并且拥有此权限。
oracle@e871d42341c0:~$ id uid=1000(oracle) gid=1000(dba) groups=1000(dba) oracle@e871d42341c0:~$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 08:20:51 2018 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> show user USER is "SYS" SQL>
方式2(本机): sqlplus 用户名/密码
在本机除了sysdba,还可以通过用户名和密码的方式登陆进来
oracle@e871d42341c0:~$ sqlplus system/liumiao123 SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 08:21:27 2018 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> show user USER is "SYSTEM" SQL>
方式3: 通过tnsname方式
通过tns设定,保证联通性的情况下使用 sqlplus 用户名/密码@Oracle实例名 的方式进行连接。
确认tns连接通畅
oracle@e871d42341c0:~$ tnsping XE TNS Ping Utility for Linux: Version 11.2.0.2.0 - Production on 21-OCT-2018 10:32:55 Copyright (c) 1997, 2011, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = e871d42341c0)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE))) OK (0 msec) oracle@e871d42341c0:~$
确认oracle的监听进程正常启动
oracle@e871d42341c0:~$ ps -ef |grep lsnr |grep -v grep oracle 27 1 0 Oct16 ? 00:00:28 /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr LISTENER -inherit oracle@e871d42341c0:~$
连接
oracle@e871d42341c0:~$ sqlplus system/liumiao123@XE SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 10:34:04 2018 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> show user USER is "SYSTEM" SQL>
方式4: IP和port的方式定位
还可通过IP和port的方式定位Oracle实例进行连接:sqlplus 用户名/密码@//IP地址或者hostname:端口号/Oracle实例名
# netstat -tunlp |grep 1521 tcp6 0 0 :::1521 :::* LISTEN - # ip ad |grep 172.17 inet 172.17.0.2/16 scope global eth0 # sqlplus system/abcd1234@//172.17.0.2:1521/XE SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 10:37:31 2018 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL>
方法5: 使用nolog 和 connect实现连接
准确的来说,这种方式和方式2/方式3/方式4没有本质区别,无非就是用户名/密码以及实例名的信息的写法不同而已,详细如下:
# sqlplus /nolog SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 11:19:50 2018 Copyright (c) 1982, 2011, Oracle. All rights reserved. SQL> connect system/liumiao123 Connected. SQL> connect system/liumiao123@XE Connected. SQL> connect system/liumiao123@//172.17.0.2:1521/XE Connected. SQL> show user USER is "SYSTEM" SQL>
相关推荐
Hody 2020-08-16
FightFourEggs 2020-08-16
yanghuatong 2020-08-16
LuoXinLoves 2020-08-09
Justdoit00 2020-06-26
娜娜 2020-06-22
Carlos 2020-07-29
lklong 2020-11-22
oraclemch 2020-11-06
shilukun 2020-10-10
周嘉笙 2020-11-09
zhuzhufxz 2020-09-16
bfcady 2020-08-16
数据库设计 2020-08-16
dbasunny 2020-08-16
罗罗 2020-08-16
ihuaqiang 2020-08-16
choice0 2020-07-30
娜娜 2020-07-28
solarspot 2020-07-28
踩风火轮的乌龟 2020-07-26
娜娜 2020-07-20
xwb 2020-07-19
娜娜 2020-07-18
流云追风 2020-07-04
dataminer 2020-06-25
zhangchaoming 2020-06-21