SQL>create user arthur identified by m123
(m123是密碼,必須是以字母開頭)
一般的普通用戶是無權限用create user的
可以切換用戶然後創建
#用system來創建用戶arthur
SQL>conn system/密碼
SQL>create user arthur identified by m123
------------------------------------------------------------------------
2.注意上面創建了arthur,但是它只是個孤零零的用戶,
沒有任何權限,所以下面的
鏈接語句也不會執行成功
SQL>conn arthur/m123,//沒有權限,運行不成功
3.爲了獲得權限,用grant,收回一個權限revoke
可以讓system來賦給arthur 權限
#首先登陸system
SQL>conn system/密碼
SQL>grant connect to arhtur 回車//system把connect權限給予arthur
授權成功
然後執行鏈接
SQL>conn arthur/m123
就成功了
--------------------------------------------------------------------------
4.讓用戶arthur有權限建表,如果不付權限的話,arthur用戶是不可以創建表的
SQL>conn system/密碼
SQL>grant resource to arthur
授權成功
SQL>conn arthur/m123
SQL>create table table_name
--------------------------------------------------------------------------
5.希望arthur用戶可以查詢scott用戶的emp表
授權者是:scott(因爲emp是裏面scott的表),
SQL>conn scott/密碼
SQL>grant select on emp to arthur
授權成功
下面如果arthur想查詢scott表emp可以用下面的語句(emp是表)
先登錄
SQL>conn arthur/m123
SQL>select * from emp;//此句錯誤
SQL>select * from scott.emp;
說明此時arthur對emp只有查詢權限
--------------------------------------------------------------------------
6.如果arthur用戶想更新scott的emp,可以用下面的授權
SQL>conn scott/密碼
SQL>grant update on emp to arthur
授權成功
說明此時arthur對emp只有更改權限
--------------------------------------------------------------------------
7.如果arthur用戶可以修改/刪除/查詢/添加scott的emp表可以用下面的語句
SQL>conn scott/密碼
SQL>grant all on emp to arthur
授權成功
收回權限(scott收回arthur對emp表的查詢權限)
SQL>conn scott/密碼
SQL> revoke select on emp from arthur
--------------------------------------------------------------------------
8'權限的傳遞,scott給arthur賦權限的同時,也允許arthur繼續把權限傳遞下去
當然arthur傳遞的權限不能超越scott所受的權限
scott>--arthur>----somebody
如果是對象權限,就加入 with grant option
SQL> conn scott/密碼
已連接
SQL>grant select on emp to arthur with grant option
下面arthur把對emp的選擇權限受權給另一個用戶 tom
#先登錄
SQL>conn arthur/m123
SQL>grant select on emp to tom //此種寫法錯誤,arthur裏面沒有emp表
SQL>grant select on scott.emp to tom
注意:當scott把arthur的權限select回收revoke時,tom對emp的select權限也是被回收了
如果是系統權限
system 賦權給arthur