溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle中如何創(chuàng)建用戶

發(fā)布時間:2021-06-21 15:04:11 來源:億速云 閱讀:160 作者:Leah 欄目:大數(shù)據(jù)

Oracle中如何創(chuàng)建用戶,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

創(chuàng)建用戶和表空間:

1、登錄linux,以oracle用戶登錄(如果是root用戶登錄的,登錄后用 su - oracle命令切換成oracle用戶)

2、以sysdba方式來打開sqlplus,命令如下: sqlplus / as sysdba

3、創(chuàng)建臨時表空間:

--查詢臨時表空間文件的絕對路徑。如果需要的話,可以通過查詢來寫定絕對路徑。一般用${ORACLE_HOME}就可以了  
select name from v$tempfile;  
create temporary tablespace NOTIFYDB_TEMP tempfile '${ORACLE_HOME}\oradata\NOTIFYDB_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;

4、創(chuàng)建表空間:

--查詢用戶表空間文件的絕對路徑:
select name from v$datafile;
create tablespace NOTIFYDB datafile '${ORACLE_HOME}\oradata\notifydb.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

5、創(chuàng)建用戶和密碼,指定上邊創(chuàng)建的臨時表空間和表空間

create user hc_notify identified by hc_password default tablespace NOTIFYDB temporary tablespace NOTIFYDB_TEMP;

6、賦予權(quán)限

grant dba to hc_notify;
grant connect,resource to hc_notify;
grant select any table to hc_notify;
grant delete any table to hc_notify;
grant update any table to hc_notify;
grant insert any table to hc_notify;

經(jīng)過以上操作,就可以使用hc_notify/hc_password登錄指定的實例,創(chuàng)建我們自己的表了。

刪除表空間:

1、查看用戶權(quán)限

--查看用戶要具備drop tablespace的權(quán)限,如果沒有,先用更高級的用戶(如sys)給予授權(quán)
select a2.username,a1.privilege from dba_sys_privs a1 , user_role_privs a2
where a1.privilege = 'DROP TABLESPACE'
and a1.grantee =a2.granted_role

2、刪除臨時表空間

復(fù)制代碼
--查看臨時表空間文件
select name from v$tempfile;
--查看用戶和表空間的關(guān)系
select USERNAME,TEMPORARY_TABLESPACE from DBA_USERS;
--如果有用戶的默認(rèn)臨時表空間是NOTIFYDB_TEMP的話,建議進(jìn)行更改
alter user xxx temporary tablespace tempdefault;
---設(shè)置tempdefault為默認(rèn)臨時表空間
alter database default temporary tablespace tempdefault;
--刪除表空間NOTIFYDB_TEMP及其包含數(shù)據(jù)對象以及數(shù)據(jù)文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles;

3.刪除用戶表空間

--查看表空間文件
select name from v$datafile;
--停止表空間的在線使用
alter tablespace 表空間名稱 offline;
--刪除表空間NOTIFYDB_TEMP及其包含數(shù)據(jù)對象以及數(shù)據(jù)文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles;

Oracle用戶權(quán)限查詢相關(guān)操作:

--查看所有的用戶
select * from all_users;
--查看當(dāng)前用戶信息
select * from user_users;
--查看當(dāng)前用戶的角色
select * from user_role_privs;
--查看當(dāng)前用戶的權(quán)限
select * from user_sys_privs;
--查看當(dāng)前用戶的表可操作權(quán)限
select * from user_tab_privs;

--查看某一個表的約束,注意表名要 大寫
select * from user_constraints where table_name='TBL_XXX';
--查看某一個表的所有索引,注意表名要 大寫
select index_name,index_type,status,blevel from user_indexes where table_name = 'TBL_XXX';
--查看索引的構(gòu)成,注意表名要 大寫
select table_name,index_name,column_name, column_position FROM user_ind_columns WHERE table_name='TBL_XXX';

--系統(tǒng)數(shù)據(jù)字典 DBA_TABLESPACES 中記錄了關(guān)于表空間的詳細(xì)信息
select * from sys.dba_tablespaces;

--查看用戶序列
select * from user_sequences;
--查看數(shù)據(jù)庫序列
select * from dba_sequences;

案例

-- 創(chuàng)建臨時表空間
create temporary tablespace PINGAN_TEMP tempfile '/u01/app/oracle/oradata/XE/PINGAN_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;  
-- 創(chuàng)建表空間
create tablespace PINGAN datafile '/u01/app/oracle/oradata/XE/pingandb.dbf' size 200M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
-- 創(chuàng)建用戶
create user pingan identified by pingan default tablespace SZNS temporary tablespace SZNS_TEMP;
-- 授權(quán)
grant dba to pingan;
grant connect,resource to pingan;
grant select any table to pingan;
grant delete any table to pingan;
grant update any table to pingan;
grant insert any table to pingan;

看完上述內(nèi)容,你們掌握Oracle中如何創(chuàng)建用戶的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI