配色: 字号:
Oracle(一)用户篇
2016-03-11 | 阅:  转:  |  分享 
  


//

sqlplus/assysdba





/1:创建表空间/

createtablespacesisimsDATAFILE

''F:\app\Administrator\oradata\orcl\sisims.DBF''SIZE5MAUTOEXTENDONNEXT10MMAXSIZEUNLIMITED;



/2:创建临时表空间--大小限制/

createtemporarytablespacesisims_temptempfile''F:\app\Administrator\oradata\orcl\sisims_temp.dbf''

size50mautoextendonnext50mmaxsize20480mextentmanagementlocal;



/2:创建临时表空间--大小无限制/

createtemporarytablespacesisims_temptempfile''F:\app\Administrator\oradata\orcl\sisims_temp.dbf''

SIZE50mautoextendONNEXT50mMAXSIZEUNLIMITED;





/删除表空间tablespace/

DROPTABLESPACEtablespace_nameINCLUDINGCONTENTSANDDATAFILES;





/:创建用户并指定表空间/

createusersisimsidentifiedbysisimsdefaulttablespacesisimstemporarytablespacesisims_temp;

createusersisimsidentifiedbysisims--简单创建用户



/:删除用户加上cascade则将用户连同其创建的东西全部删除/

dropuser用户名cascade;





/3:给用户授予权限/

grantdbatosisims;

grantdbatosisims,sisimsbi;



grantconnect,resourcetosisims;

grantcreatesessiontosisims;







grantconnect,resource,dbatousername;

grantcreatetable,createsequence,createview,createproceduretosisims;

grantunlimitedtablespacetosisims;--授予不限制的表空间



--or



grantcreatetabletosisims;

grantcreateviewtosisims;

grantcreateproceduretosisims;

grantcreatesequencetosisims;



grantcreateanyviewtosisims;

grantcreateanytabletosisims;

grantcreateanyproceduretosisims;

grantcreateanytriggertosisims;

grantcreateanysequencetosisims;

grantdeleteanytabletosisims;

grantinsertanytabletosisims;

grantdropanytabletosisims;

grantselectanytabletosisims;--授予查询任何表

grantselectanydictionarytosisims;--授予查询任何字典



grantalltopublic;--这条比较重要,授予所有权限(all)给所有用户(public)









---------------------------------





grantcreatesessiontoTEST;--授予TEST用户创建session的权限,即登陆权限

grantunlimitedsessiontoTEST;--授予TEST用户使用表空间的权限

grantcreatetabletoTEST;--授予创建表的权限

grantdroptabletoTEST;--授予删除表的权限

grantinserttabletoTEST;--插入表的权限

grantupdatetabletoTEST;--修改表的权限



--oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的

grantselectontablenametoTEST;--授予TEST用户查看指定表的权限

grantdropontablenametoTEST;--授予删除表的权限

grantinsertontablenametoTEST;--授予插入的权限

grantupdateontablenametoTEST;--授予修改表的权限











=======================================================



#http://www.cnblogs.com/NaughtyBoy/p/3185099.html



1、显示当前用户名

selectuserfromdual;

showuser



2、显示当然用户有哪些表

selectfromtab;



3、显示当所有用户的表

selectfromuser_tables;



4、显示当有用户可以访问表

selectfromall_tables;



5、显示用户为SCOTT的表

selectfromdba_tableswhereowner=''SCOTT'';



6、显示所有用户名和帐户的状态

selectusername,account_statusfromdba_users;



7、显示所有用户信息

selectfromdba_users;



8、将SCOTT帐号解锁(加锁)

alteruserscottaccountunlock(lock);



9、当前用户的缺省表空间

SELECTDEFAULT_TABLESPACEFROMDBA_USERSWHEREUSERNAME=(selectuserfromdual);



10、显示当前数据库的用户

SELECTUSERNAME,ACCOUNT_STATUS,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACEFROMDBA_USERS;



11、建立一个新用户

createuseredpthwidentifiedby"123456"

defaulttablespaceusers

temporarytablespacetemp

quotaunlimitedonusers

quota10monmytbs2;







##修改用户密码:

selectusername,passwordfromdba_userswhereusername=''system'';

alterusersystemidentifiedby密码;

alterusersystemidentifiedbysystem;





##修改用户解锁:

alterusersystemaccountunlock;



##删除用户

dropuseruser01;







12、给用户授权

grantconnect,resourcetoedpthw;



13、分别授权

GRANTCREATEANYTABLETO"hmtong"

GRANTCREATETABLETO"hmtong"

GRANTDROPANYTABLETO"hmtong"

GRANTSELECTANYTABLETO"hmtong"



14、对象授权

GRANTSELECTON"hmtong"."A"TO"edpthw"



15、折消授权

REVOKEUNLIMITEDTABLESPACEFROM"hmtong"



16、折消对象授权

REVOKESELECTON"hmtong"."A"FROM"edpthw"



17、用户改密码

alteruseredpthwidentifiedbyedpthw;



18、授权sysdba给指定用户

grantsysdbatohmtong;



19、取消指定用户的sysdba权限

revokesysdbafromhmtong;



20、修改系统的授权的属性

altersystemsetremote_login_passwordfile=exclusive;



能sysdba登录,能授权

altersystemsetremote_login_passwordfile=sharedscope=spfile;只能sysdba登录,不能授权

altersystemsetremote_login_passwordfile=NONE;取消



21、授权连接给指定用户

GRANT"CONNECT"TO"hmtong";GRANTUNLIMITEDTABLESPACE,CONNECT,RESOURCETOHMTONG;



22、查询Pwfile中存放的用户信息

selectfromv$pwfile_users;







-------------------



--表空间

CREATETABLESPACEsdt

DATAFILE''F:\tablespace\demo''size800M

EXTENTMANAGEMENTLOCALSEGMENTSPACEMANAGEMENTAUTO;

--索引表空间

CREATETABLESPACEsdt_Index

DATAFILE''F:\tablespace\demo''size512M

EXTENTMANAGEMENTLOCALSEGMENTSPACEMANAGEMENTAUTO;



--2.建用户

createuserdemoidentifiedbydemo

defaulttablespacedemo;



--3.赋权

grantconnect,resourcetodemo;

grantcreateanysequencetodemo;

grantcreateanytabletodemo;

grantdeleteanytabletodemo;

grantinsertanytabletodemo;

grantselectanytabletodemo;

grantunlimitedtablespacetodemo;

grantexecuteanyproceduretodemo;

grantupdateanytabletodemo;

grantcreateanyviewtodemo;





-----------------













================================================





下面参考:





新建表空间(SEVEN):

CREATETABLESPACESEVEN

LOGGING

DATAFILE''D:\app\seven\oradata\orcl\seven.DBF''

SIZE32M

AUTOEXTENDON

NEXT32MMAXSIZE2096M

EXTENTMANAGEMENTLOCAL;





新建用户(seven),密码(seven),默认表空间SEVEN:

CREATEUSERsevenIDENTIFIEDBYseven

DEFAULTTABLESPACESEVEN;





授权:

grantdbaTOSEVEN;

GRANT

CREATESESSION,CREATEANYTABLE,CREATEANYVIEW,CREATEANYINDEX,CREATEANYPROCEDURE,

ALTERANYTABLE,ALTERANYPROCEDURE,

DROPANYTABLE,DROPANYVIEW,DROPANYINDEX,DROPANYPROCEDURE,

SELECTANYTABLE,INSERTANYTABLE,UPDATEANYTABLE,DELETEANYTABLE

TOSEVEN;







-----------------------------------------------



/建立表空间(一般建N个存数据的表空间和一个索引空间):/

createtablespace表空间名

datafile''路径(要先建好路径)\.dbf''sizeM

tempfile''路径\.dbf''sizeM

autoextendon--自动增长

--还有一些定义大小的命令,看需要

defaultstorage(

initial100K,

next100k,

);







-----------------------------------------------

/分为四步/

/第1步:创建临时表空间/

createtemporarytablespaceuser_temp

tempfile''D:\oracle\oradata\Oracle9i\user_temp.dbf''

size50m

autoextendon

next50mmaxsize20480m

extentmanagementlocal;



/第2步:创建数据表空间/

createtablespaceuser_data

logging

datafile''D:\oracle\oradata\Oracle9i\user_data.dbf''

size50m

autoextendon

next50mmaxsize20480m

extentmanagementlocal;



/第3步:创建用户并指定表空间/

createuserusernameidentifiedbypassword

defaulttablespaceuser_data

temporarytablespaceuser_temp;



/第4步:给用户授予权限/

grantconnect,resource,dbatousername;







==========================================











献花(0)
+1
(本文系眼界999首藏)