oracle各種用戶登錄的方式


Oracle有3種用戶: system、sys、scott

1、system和sys的差別在與是否能創建數據庫
2、sys用戶登錄創建數據庫,
3、scott是給剛開始學習的人學習的用戶。學習者能夠用Scott登錄系統,注意scott用戶登錄后,就能夠使用Oracle提供的數據庫和數據表,這些都是oracle提供的。

sqlplus
//這種方式,直接提示輸入用戶名和密碼
[oracle@shdb02 ~]$ sqlplus SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 20:28:02 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved. Enter user-name:

 sqlplus /nolog

//這種方式,不會提示用戶名和密碼,但是並沒有登錄任何oracle
[oracle@shdb02 ~]$ echo $ORACLE_SID
htstandby2
[oracle@shdb02 ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 20:30:39 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.

//這個時候,你輸入sql,提示未連接
SQL> select value from v$parameter where name='instance_name';
SP2-0640: Not connected
//要進行連接,登錄
SQL> conn /as sysdba
Connected.
SQL> select value from v$parameter where name='instance_name';
VALUE
--------------------------------------------------------------------------------
htstandby2

一、sqlplus /nolog登錄方式

//為防止看到密碼,直接用這種方式
[oracle@shdb02 expdir]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:01:17 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL>

演示1:sqlplus /nolog (conn ./as sysdba)

oracle@prd:/home/oracle$sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 20:39:42 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn ./as sysdba
Enter password: 
Connected.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

//我們history一下
1041 conn ./as sysdba
1042 sqlplus 
1043 sqlplus /nolog
1044 sqlplus
1045 history
//並沒有看到密碼

演示2:sqlplus /nolog (conn /as sysdba) 
 //conn /as sysdba操作系統認證登錄

oracle@prd:/home/oracle$sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 20:39:42 2022
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
SQL>  conn /as sysdba
Connected.

演示3: sqlplus /nolog(conn username/passwd)


//一般是啟動sqlplus但不進行連接操作,nolog 選項會啟動sqlplus, 但不連接數據庫,但是也可以連接
[oracle@shdb02 expdir]$ echo $ORACLE_SID
fpmai2
[oracle@shfpdb02 expdir]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:07:29 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
//進入sqlplus 輸入用戶名和密碼
SQL> conn sh/Shdb12
Connected.
SQL> select value from v$parameter where name='instance_name';
VALUE
--------------------------------------------------------------------------------
fp2
[oracle@shdb02 ~]$ sqlplus / as sysdba

 

二、sqlplus登錄方式

//直接啟動sqlplus,進入sqlplus命令行,提示進入哪個用戶
[oracle@shdb02 expdir]$ sqlplus
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:02:39 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name: shfp
Enter password: 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>

 

三、sqlplus / as sysdba 登錄方式
//這種方式是直接登錄了實例,當然也可以連接其他用戶

演示1

[oracle@shdb02 ~]$ echo $ORACLE_SID
fpmai2
[oracle@shfpdb02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:17:46 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
//查看當前的實例
SQL> select value from v$parameter where name='instance_name';
VALUE
--------------------------------------------------------------------------------
fp2
//查詢當前的用戶
SQL> select user from dual;
USER
--------------------------------------------------------------------------------
SYS
//如果你想連其他用戶,設置錯誤
SQL> conn shp/sr
ERROR:
ORA-00942: table or view does not exist
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM


//下面是具體的操作過程,出現錯誤----- 1、實例和用戶不匹配的
[oracle@shdb02 ~]$ echo $ORACLE_SID
ht 
[oracle@shdb02 ~]$ sqlplus /nolog //(進入sqlplus環境,不登錄)
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:24:54 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn shp/Shdbrrrr    //shp用戶為fp實例的用戶,並不是ht的,所以出現錯誤
ERROR:
ORA-01017: invalid username/password; logon denied
SQL> exit
//進入fp實例 [oracle@shdb02
~]$ export ORACLE_SID=fp [oracle@shdb02 ~]$ sqlplus /nolog SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:25:23 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved. SQL> conn shp/sr Connected.
//查看當前登錄用戶
SQL> select user from dual;
USER
------------------------------
SH
//查看該用戶所屬的表空間
SQL> select * from dba_tablespaces;

 演示2:

//如果你想查表空間,需要登錄某個用戶,而不是SYS用戶
[oracle@shdb02 ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:33:18 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> select * from dba_tablespaces;
SP2-0640: Not connected

手工建庫之后登錄

oracle@prd:/home/oracle$export ORACLE_SID=fp
oracle@prd:/home/oracle$echo $ORACLE_SID
fp
oracle@prd:/home/oracle$sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:04:35 2022
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
SQL> select value from v$parameter where name='instance_name';
SP2-0640: Not connected
SQL> conn sh/sh12
ERROR:
ORA-00942: table or view does not exist
Error accessing PRODUCT_USER_PROFILE
Warning:  Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Connected.
//出現上面的提示,這種提示會導致很多其他操作也會失敗.下面有解決方式
//解決辦法
 
         
  需要使用system用戶登陸並執行 pupbld.sql腳本,每個安裝不同,所以這個腳本位置不同
 
         

 oracle@prd:/home/oracle$locate pupbld.sql
/u01/oracle/product/11.2.0/sqlplus/admin/pupbld.sql

oracle@prd:/home/oracle$sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:17:12 2022

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

SQL> conn /as sysdba  //超級管理員身份登錄
Connected.

//修改system的密碼,這個當中,system密碼已找不到,需要重新修改密碼

SQL> alter user system identified by abci12;

User altered.

SQL> conn system/abc12
Connected.
//執行pupbld.sql

SQL> @/u01/oracle/product/11.2.0/sqlplus/admin/pupbld.sql
DROP SYNONYM PRODUCT_USER_PROFILE
*
ERROR at line 1:
ORA-01434: private synonym to be dropped does not exist

DATE_VALUE FROM PRODUCT_USER_PROFILE
*
ERROR at line 3:
ORA-00980: synonym translation is no longer valid

DROP TABLE PRODUCT_USER_PROFILE
*
ERROR at line 1:
ORA-00942: table or view does not exist

ALTER TABLE SQLPLUS_PRODUCT_PROFILE ADD (LONG_VALUE LONG)
*
ERROR at line 1:
ORA-00942: table or view does not exist

Table created.

DROP TABLE PRODUCT_PROFILE
*
ERROR at line 1:
ORA-00942: table or view does not exist

DROP VIEW PRODUCT_PRIVS
*
ERROR at line 1:
ORA-00942: table or view does not exist

View created.

Grant succeeded.

Synonym dropped.

Synonym created.

DROP SYNONYM PRODUCT_USER_PROFILE
*
ERROR at line 1:
ORA-01434: private synonym to be dropped does not exist

Synonym created.

Synonym dropped.

Synonym created.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
oracle@prod:/home/oracle$sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 21:25:15 2022

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

//連接成功

SQL> conn sh/sh12
Connected.

 

###################登錄系統賬戶############################################################################################################
as sysdba 就是以sysdba登錄,oracle登錄身份有三種:

1、normal 普通身份;
2、sysdba 系統管理員身份;
啟動和關閉操作
更改數據庫狀態為打開/裝載/備份,更改字符集
創建數據庫
創建服務器參數文件spfile
日志歸檔和恢復
包含了“會話權限”權限
3、sysoper 系統操作員身份。
啟動和關閉操作
更改數據庫狀態為打開/裝載/備份
創建服務器參數文件SPFILE
日志歸檔和恢復
包含了“會話權限”權限

數據庫用sysdba登錄的驗證有兩種方式,
一種是通過OS認證,
一種是通過密碼文件驗證;登錄方式有兩種,
一種是在數據庫主機直接登錄(用os認證的方式)。

演示 sys 登錄方式

[oracle@shdb02 ~]$ sqlplus
SQL*Plus: Release 11.2.0.4.0 Production on Sat Mar 19 21:53:42 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name: sys as sysdba
Enter password:**********
/****
還可以這樣
sqlplus sys as sysdba
Enter user-name:sys
Enter password:password as sysdba --以sys用戶登陸的話 必須要加上 as sysdba 子句
**/

演示 sqlplus + sys as sysdba 方式登錄,直接輸入密碼

[oracle@shdb02 ~]$ sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:43:30 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter password: ******
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> 
SQL> select user from dual; //查看當前用戶
USER
------------------------------
SYS

 

進入51.10的sys 用戶下

演示1:

//當前實例fp
oracle@prd:/home/oracle$echo $ORACLE_SID
fpmai
oracle@prd:/home/oracle$sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:12:16 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter password: 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select user from dual; 
USER
--------------------------------------------------------------------------------
SYS
SQL>set pagesize 0 
SQL>set line 8888
SQL>select * from dba_tablespaces; 

演示2:
//我們在換一個實例prd看下

oracle@prd:/home/oracle$sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 20 19:12:16 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved. Enter password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select user from dual; USER -------------------------------------------------------------------------------- SYS //顯示的是這個實例的內容 SQL> select * from dba_tablespaces; //查看當前用戶 SQL> show user; USER is "SYS" //查看當前數據庫實例 SQL> show parameter instance_name; instance_name string prd

 四、演示默認學習用戶scott,默認密碼是tiger

oracle@prd:/home/oracle$sqlplus /nolog
SQL> conn scott/tiger
ERROR:
ORA-28000: the account is locked

SQL> exit
oracle@prd:/home/oracle$sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 21 20:28:21 2022

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

SQL> conn / as sysdba  //用超級管理賬戶登錄
Connected.
SQL> alter user scott account unlock;   //解鎖

User altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

//重新登錄sqlplus軟件,/nolog表示沒有任何用戶登錄
oracle@prd:/home/oracle$sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 21 20:28:53 2022

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

SQL> conn scott/tiger  //提示密碼已過期,重新設置
ERROR:
ORA-28001: the password has expired
Changing password for scott
New password: 
Retype new password: 
Password changed
Connected.

  SQL> show user;
  USER is "SCOTT"

SQL>alter user scott identified by tiger;  

  User altered.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM