Oracle中su切換進去sqlplus登入失敗的問題處理

來源:互聯網
上載者:User

Oracle中su切換進去sqlplus登入失敗的問題處理

問題描述:
生產環境的Oracle資料庫突然登入不上去了,rlwrap生產環境的oracle資料庫突然登入不上去了,rlwrap sqlplus "/ as sysdba"報錯如下:rlwrap
[oracle@localhost root]$ rlwrap sqlplus "/ as sysdba"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.
rlwrap: Cannot execute sqlplus: Permission denied
[oracle@localhost root]$ sqlplus "/ as sysdba"
bash: sqlplus: command not found
[oracle@localhost root]$

1,oracle登入報錯
[oracle@localhost root]$  rlwrap sqlplus "/ as sysdba"
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
[oracle@localhost root]$
[oracle@localhost root]$

2,查看ORACLE_HOME變數,為空白值
[oracle@localhost root]$ echo $ORACLE_HOME

[oracle@localhost root]$

3,在/etc/profile設定ORACLE_HOME變數
[root@localhost ~]# vim /etc/profile
export ORACLE_HOME=/opt/oracle/app/oracle/product/11.2.0/dbhome_1

[root@localhost ~]# source /etc/profile
[root@localhost ~]# su oracle
[oracle@localhost root]$
[oracle@localhost root]$ echo $ORACLE_HOME
/oracle/app/oracle/product/11.2.0/dbhome_1/
[oracle@localhost root]$

4,ORACLE_HOME環境變數有值了,再去用sqlplus登入一下,試試看
[oracle@localhost root]$ rlwrap sqlplus "/ as sysdba"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.
rlwrap: Cannot execute sqlplus: Permission denied
[oracle@localhost root]$

5,做一下sqlplus的軟串連
[oracle@localhost root]$ exit
exit
[root@localhost ~]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
[root@localhost ~]# su oracle
[oracle@localhost root]$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 16 10:19:39 2015

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


ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified

SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[oracle@localhost root]$
[oracle@localhost root]$ echo $ORACLE_SID

[oracle@localhost root]$
系統內容變數裡面沒有ORACLE_SID

6,設定ORACLE_SID
[oracle@localhost root]$ exit
exit
[root@localhost ~]# vim /etc/profile
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=pxxerxxs
[root@localhost ~]#  source /etc/profile

[oracle@localhost root]$ exit
exit
[root@localhost ~]# vim /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# su oracle
[oracle@localhost root]$ rlwrap sqlplus "/ as sysdba"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.
                                                                                                                                                                                              SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 16 10:25:33 2015

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

Connected to an idle instance.                                                                                                                                                               

SQL>                                                                                                                                                                                         
SQL>                                                                                                                                                                                         
SQL>

7,去oracle使用者下查看系統變數
[oracle@localhost root]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi


# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH


#added for oracle
export ORACLE_BASE=/oracle/app/oracle
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=pxxerxxs
export TNS_ADMIN=$ORACLE_HOME/network/admin

export PATH=$PATH:$ORACLE_HOME/bin
[oracle@localhost root]$
配置裡面有值,問題在哪裡?

8,su的時候有差異
不加-的話的話只是切換使用者 不去更換使用者的配置,加上-後 再去sqlplus 試試
[oracle@localhost ~]$ exit
logout
[root@localhost ~]# su oracle
[oracle@localhost root]$ echo $ORACLE_BASE


[oracle@localhost root]$ exit
exit
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ echo $ORACLE_BASE
/oracle/app/oracle
[oracle@localhost ~]$

9,驗證下su - oracle
[oracle@localhost ~]$ rlwrap sqlplus "/ as sysdba"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.
                                                                                                                                                                                             
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 16 10:36:51 2015

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

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

SQL>

10,OK,嘗試使用非sys帳號登入報錯
[oracle@localhost ~]$ rlwrap sqlplus "plas_prd/plrd_1628@pxxerxxs as sysdba"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 16 16:53:11 2015

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

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

Enter user-name:                                                                                                                                                                             
ERROR:
ORA-01017: invalid username/password; logon denied


Enter user-name:                                                                                                                                                                             
[oracle@localhost ~]$

11,去check下,tnsping pxxerxxs 能否成功
[oracle@localhost ~]$ tnsping  pxxerxxs

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 16-JAN-2015 16:53:27

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

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

TNS-03505: Failed to resolve name
[oracle@localhost ~]$
tnsping失敗,得知pxxerxxs這個失效

12,去找tnsnames.ora
[oracle@localhost admin]$  more /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
也可以more $ORACLE_HOME/network/admin/tnsnames.ora
找到
MPMD2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.110.107)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME= pxxerxxs)
    )
  )

然後用非sys使用者登入
[oracle@localhost ~]$ rlwrap sqlplus "pxxerxxsk/pa141215@MPMD2"
rlwrap: warning: your $TERM is 'xterm' but rlwrap couldn't find it in the terminfo database. Expect some problems.

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 16 20:30:30 2015

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

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

SQL>

OK登入顯示成功。

總結,
(1)linux系統裡面,su切換到oracle使用者的時候,加上-就會更換oracle使用者單獨配置生效,如果不加-就不會使用oracle使用者單獨的配置。
(2)在使用sqlplus登入的時候,用非sys使用者登入,@後面的是$ORACLE_HOME/network/admin/tnsnames.ora定義的那個首碼符號MPMD2,而不是SERVICE_NAME所指的oracle_sid,tnsnames.ora中MPMD2首碼定義如下所示
MPMD2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.110.101)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME= pxxerxxs)
    )
  )

Oracle學習筆記:sqlplus使用者登入

sqlplus登入Oracle時ORA-01017: invalid username/password; logon denied的錯誤 

在CentOS 6.4下安裝Oracle 11gR2(x64)

Oracle 11gR2 在VMWare虛擬機器中安裝步驟

Debian 下 安裝 Oracle 11g XE R2

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.