1. 程式人生 > >為什麽以sys無法遠程登錄數據庫

為什麽以sys無法遠程登錄數據庫

event users app 但是 version 無法解析名稱 protoc res with

今天通過pl/sql連接一個數據庫,普通用戶能連接上,但是sys就連接不上,告訴我用戶名密碼錯誤。之前其實遇到過這個問題,然後就開始查找原因。整個過程記錄如下,結果是紮心的,過程也不是完全都懂。記下來權當備忘吧。

1、查看服務器監聽器狀態。

技術分享
 1 $ lsnrctl status
 2 
 3 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 13-9月 -2017 18:07:36
 4 
 5 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 6 
 7 正在連接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oa-db-01
)(PORT=1521))) 8 LISTENER 的 STATUS 9 ------------------------ 10 別名 LISTENER 11 版本 TNSLSNR for Linux: Version 11.2.0.1.0 - Production 12 啟動日期 13-9月 -2017 17:25:29 13 正常運行時間 00 小時 42714 跟蹤級別 off 15 安全性 ON: Local OS Authentication
16 SNMP OFF 17 監聽程序參數文件 /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora 18 監聽程序日誌文件 /oracle/app/diag/tnslsnr/oa-db-01/listener/alert/log.xml 19 監聽端點概要... 20 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oa-db-01)(PORT=1521))) 21 服務摘要.. 22 服務 "PLSExtProc" 包含 1
個實例。 23 實例 "PLSExtProc", 狀態 UNKNOWN, 包含此服務的 1 個處理程序... 24 服務 "orcl" 包含 1 個實例。 25 實例 "orcl", 狀態 READY, 包含此服務的 1 個處理程序... 26 服務 "orclXDB" 包含 1 個實例。 27 實例 "orcl", 狀態 READY, 包含此服務的 1 個處理程序... 28 命令執行成功
View Code

可以看到監聽器沒有問題。

2、通過tnsping查看是否能夠連通。

在服務器上做

技術分享
 1 $ tnsping orcl
 2 
 3 TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 13-9月 -2017 18:09:28
 4 
 5 Copyright (c) 1997, 2009, Oracle.  All rights reserved.
 6 
 7 已使用的參數文件:
 8 /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora
 9 
10 TNS-03505: 無法解析名稱
View Code

這是因為服務器上沒有tnsname.ora這個配置文件,無法解析名稱。

在客戶端上做

技術分享
 1 tnsping oaproddb
 2 
 3 TNS Ping Utility for 32-bit Windows: Version 11.2.0.4.0 - Production on 13-9月 -2017 18:11:05
 4 
 5 Copyright (c) 1997, 2013, Oracle.  All rights reserved.
 6 
 7 已使用的參數文件:
 8 D:\app\JIAKAI\product\11.2.0\client_1\network\admin\sqlnet.ora
 9 
10 
11 已使用 TNSNAMES 適配器來解析別名
12 嘗試連接 (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = **.**.**.**)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
13 OK (20 毫秒)
14 
15 C:\Users\JIAKAI>
View Code

沒有問題。

3、查看數據庫參數文件

登錄到服務器,然後以sys用戶登錄到數據庫

技術分享
 1 $ sqlplus / as sysdba
 2 
 3 SQL*Plus: Release 11.2.0.1.0 Production on 星期三 9月 13 18:16:12 2017
 4 
 5 Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 6 
 7 
 8 連接到: 
 9 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
10 With the Partitioning, OLAP, Data Mining and Real Application Testing options
11 
12 SQL> show user
13 USER 為 "SYS"
14 SQL> 
View Code

4、查看spfile是否存在

技術分享
1 SQL> show parameter spfile
2 
3 NAME                                 TYPE        VALUE
4 ------------------------------------ ----------- ------------------------------
5 spfile                               string      /oracle/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora
View Code

沒有問題。

5、然後查看remote_login_pass參數

技術分享
1 SQL> show parameter remote_login_pass
2 
3 NAME                                 TYPE        VALUE
4 ------------------------------------ ----------- ------------------------------
5 remote_login_passwordfile            string      EXCLUSIVE
View Code

也沒有問題。

一直也沒有懷疑過sys密碼不正確,因為通過以下語句可以登錄

技術分享
 1 $ sqlplus sys/1234 as sysdba
 2 
 3 SQL*Plus: Release 11.2.0.1.0 Production on 星期三 9月 13 17:44:46 2017
 4 
 5 Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 6 
 7 
 8 連接到: 
 9 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
10 With the Partitioning, OLAP, Data Mining and Real Application Testing options
View Code

但還是試著抱一抱的態度,我更改了sys密碼。然後居然登錄成功了。(心裏一萬只草泥馬奔過)

那麽問題來了,為什麽sqlplus sys/1234 as sysdba能夠登錄呢?我之後又試了其他的sqlplus ***/*** as sysdba都可以登錄。(WTF)

這是因為,sqlplus ***/*** as sysdba是本地登錄,也就是操作系統登錄驗證,oracle會忽略“/”兩遍的用戶名和密碼。所以以這種方式登錄上去就是sys用戶。

所以這次的問題就是sys密碼沒有寫對,所以pl/sql登錄不上去。

參考:

http://blog.csdn.net/zdwzzu2006/article/details/6096322

http://www.cnblogs.com/kerrycode/archive/2013/03/27/2984152.html

http://blog.csdn.net/ma1kong/article/details/38636965

為什麽以sys無法遠程登錄數據庫