您好,登錄后才能下訂單哦!
怎么在Oracle中使用sqlplus連接數(shù)據(jù)庫?相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
方式1(本機(jī)): / as sysdba
在oracle服務(wù)器,可以直接通過操作系統(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 用戶名/密碼
在本機(jī)除了sysdba,還可以通過用戶名和密碼的方式登陸進(jìn)來
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設(shè)定,保證聯(lián)通性的情況下使用 sqlplus 用戶名/密碼@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)聽進(jìn)程正常啟動
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實(shí)例進(jìn)行連接:sqlplus 用戶名/密碼@//IP地址或者h(yuǎn)ostname:端口號/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)確的來說,這種方式和方式2/方式3/方式4沒有本質(zhì)區(qū)別,無非就是用戶名/密碼以及實(shí)例名的信息的寫法不同而已,詳細(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>
看完上述內(nèi)容,你們掌握怎么在Oracle中使用sqlplus連接數(shù)據(jù)庫的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。