Oralce12 自带工具sql developer 创建
1.创建临时表空间
create temporary tablespace 临时空间名称
tempfile 'D:\dbtemp.dbf'
size 5m
autoextend on
next 5m maxsize 20480m
extent management local;
-------------------------------------------
2.创建数据表空间
create tablespace 空间名称
datafile 'D:\db.dbf'
size 5m
autoextend on
next 5m maxsize 20480m
extent management local;
------------------------------------------------------------
--例子
create tablespace TEST datafile 'D:\Tools\oracle_space\All_tablespace\TEST0726.BDF' size 100m;
create user test identified by test default tablespace TEST;
grant create session to test;
grant unlimited tablespace to test;
3.创建用户并指定表空间
create user 用户名 identified by 密码 default tablespace 空间名称
temporary tablespace 临时空间名称;
4.给用户授予权限
grant connect,resource,dba to 用户;
--授权更多的权限
grant create session, connect, resource to xxx;
删除用户与表空间
1.删除user
drop user ×× cascade;
说明: 删除了user,只是删除了该user下的schema objects,是不会删除相应的tablespace的。
2.删除tablespace
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;
备份数据库
exp userid=hudong/hudong@sales file=D:\appprd20140310.dmp
还原数据库
imp hudong/hudong@testsales full = y file=e:\appprd20140311.dmp ignore=y
用户授权相关
--创建用户
create user test identified by test;
这样就创建了一个用户名密码都为test的用户 但这个时候test还是不能登陆成功的,我们需要赋予相应的权限
--赋予create session权限
grant create session to test;
这样test用户就能成功登录进去
赋予用户创建表的权限
grant create table to test;
赋予相应的权限
grant unlimited tablespace to test;
这个时候用户就拥有了创建表的权限 由于表是用户test的,相应的他就拥有了对创建的表的增删查改的权限了
--撤销权限
revoke create table from test;
--删除用户
drop user 用户名;
若用户拥有对象,则不能直接删除,否则将返回一个错误值。指定关键字cascade,可删除用户所有的对象,然后再删除用户。
drop user 用户名 cascade;
--授权操作
grant select on tabel1 to tabel2;
grant update on tabel1 to tabel2;
--授权存储过程
grant execute on procedure1 to tabel2;
-角色
create role farxix;--建立farxix角色
grant insert on table1 to farxix; --将插入表的信息
revoke insert on table1 from xujin1; --收回farxix角色的权限
grant farxix to farxix1; --将角色的权限授权给farxix1;
create role farxix1;
grant farxix1 to farxix2; --将角色farxix1授权给farxix2;
alter user farxix default farxix1,farxix2; --修改用户默认角色
drop role farxix1;--删除角色farxix1;
--------------------------------------------
备份
--数据库备份(迁移)
--cmd窗口
--导出dmp文件
exp workflowDB/workflowDB@orcl1 file=d:\workflowDB_0731.dmp owner=(workflowDB)
--sqlplus /nolog;
conn / as sysdba;
--创建表空间的语句
create tablespace zhao datafile'C:\tablespace\zhao.dbf'
size 500M
autoextend on
next 10M
--创建用户,创建用户的语句如下
create user workflowDB identified by workflowDB default tablespace zhao;
--对用户授权
grant resource,connect,dba,create view,create sequence to workflowDB;
--提交
Commit;
至此新数据库创建完毕,下一步导入数据库文件到该用户下
关闭cmd命令行,再重新打开一个cmd
输入如下imp命令导入数据库的dmp文件
Imp wsyy(刚刚输入的数据库名)/wsyy(刚刚输入的数据库密码) file=D:\wsyy.DMP(存放dmp文件的路径) full=y ignore=y;
看到命令行成功导入的提示信息则导入成功。
Imp workflowDB/workflowDB file=D:\workflowDB.dmp full=y ignore=y;