通過(guò)sqlplus可以連接數(shù)據(jù)庫(kù)根據(jù)用戶(hù)權(quán)限進(jìn)行數(shù)據(jù)或者設(shè)定操作,這篇文章介紹一下常用的連接方式。
環(huán)境準(zhǔn)備
使用Oracle的精簡(jiǎn)版創(chuàng)建docker方式的demo環(huán)境,詳細(xì)可參看:
- https://www.jb51.net/article/153533.htm
方式1(本機(jī)): / as sysdba
在oracle服務(wù)器,可以直接通過(guò)操作系統(tǒng)權(quán)限認(rèn)證,使用sysdba方式登陸,前提是你可以登入服務(wù)器,并且擁有此權(quán)限。
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(本機(jī)): sqlplus 用戶(hù)名/密碼
在本機(jī)除了sysdba,還可以通過(guò)用戶(hù)名和密碼的方式登陸進(jìn)來(lái)
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: 通過(guò)tnsname方式
通過(guò)tns設(shè)定,保證聯(lián)通性的情況下使用 sqlplus 用戶(hù)名/密碼@Oracle實(shí)例名 的方式進(jìn)行連接。
確認(rèn)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:~$
確認(rèn)oracle的監(jiān)聽(tīng)進(jìn)程正常啟動(dòng)
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的方式定位
還可通過(guò)IP和port的方式定位Oracle實(shí)例進(jìn)行連接:sqlplus 用戶(hù)名/密碼@//IP地址或者h(yuǎn)ostname:端口號(hào)/Oracle實(shí)例名
# 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實(shí)現(xiàn)連接
準(zhǔn)確的來(lái)說(shuō),這種方式和方式2/方式3/方式4沒(méi)有本質(zhì)區(qū)別,無(wú)非就是用戶(hù)名/密碼以及實(shí)例名的信息的寫(xiě)法不同而已,詳細(xì)如下:
# 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>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
您可能感興趣的文章:- Oracle SQLPlus導(dǎo)出數(shù)據(jù)到csv文件的方法
- Oracle基礎(chǔ):程序中調(diào)用sqlplus的方式
- Oracle基礎(chǔ):通過(guò)sqlplus執(zhí)行sql語(yǔ)句后的結(jié)果進(jìn)行判斷
- 使用sqlplus命令行工具為oracle創(chuàng)建用戶(hù)和表空間
- oracle11g管理員密碼忘記怎么辦 sqlplus解決忘記密碼問(wèn)題
- Linux下Oracle中SqlPlus時(shí)上下左右鍵亂碼問(wèn)題的解決辦法
- oracle 中 sqlplus命令大全
- Oracle Sqlplus命令登錄多種方式案例講解