1,这里介绍两种数据库导入导出方式,分别是imp/exp与impdp/expdp(数据泵)
2.先介绍一下imp/exp
imp(需要建立表空间,管理员身份运行)
-------首先创建表空间
create tablespace
表空间名
logging
datafile '表空间保存路径
+表空间名.dbf'
size 200m
autoextend on
next 200m maxsize unlimited --自动拓展,大小无限
extent management local;--本地管理,对应的有uniform管理,统一大小分配(UNIFORM)则是由用户指定extents大小,默认1M大小
------创建用户
create user
用户名 identified by
密码 default tablespace
表空间名;
-----给用户授权
grant resource,connect,dba to
用户名;--不同的角色对应不同的权限,resource开发人员权限,connect典型的终端用户角色,dba为数据库创建者(具体有好几个人可设置权限,如exp_full_database, --拥有导出数据库的权限,imp_full_database )
---导入数据库【命令窗口中执行】
imp
用户名/密码@数据库fromuser=
导出方 touser=
导入方 rows=y indexes=y commit=y buffer=65536 feedback=100000 ignore=n file=导入的dmp文件
.dmp log=
F:\日志文件.log----y是yes,n是no
3,exp导出
exp
用户名/密码
@数据库 rows=y indexes=y compress=n buffer=65536 feedback=100000 file=
导出.dmp log=
导出.log
4,导入指定表
imp
用户名/密码
@数据库 fromuser=
导出方 touser=
导入方 rows=y indexes=y commit=y buffer=65536 feedback=100000 ignore=n file=
导入的dmp文件
.dmp
tables=(k_0001,k_0002) log=F:\导出.log
--查看用户拥有那些角色
select * from dba_role_privs a where a.grantee='XCJ01';
--或
select * from dba_sys_privs a where a.grantee='XCJ01';
--查看角色拥有哪些权限
select ROLE, PRIVILEGE from role_sys_privs where role='RESOURCE'; --RESOURCE,CONNECT,DBA
--或
select grantee,privilege from dba_sys_privs where grantee='RESOURCE';
--为用户取消角色
revoke resource from XCJ01;
--为用户取消权限
revoke unlimited tablespace from XCJ01;
--查看Oracle版本
select * from v$version where rownum <=1;
select * from dba_role_privs a where a.grantee='XCJ01';
--或
select * from dba_sys_privs a where a.grantee='XCJ01';
--查看角色拥有哪些权限
select ROLE, PRIVILEGE from role_sys_privs where role='RESOURCE'; --RESOURCE,CONNECT,DBA
--或
select grantee,privilege from dba_sys_privs where grantee='RESOURCE';
--为用户取消角色
revoke resource from XCJ01;
--为用户取消权限
revoke unlimited tablespace from XCJ01;
--查看Oracle版本
select * from v$version where rownum <=1;
3.expdp/impdp(与imp比较)
1、把用户usera的对象导入到userb
先创建目录
create directory dir_dp as 'D:\dbbak';
然后导入如下,其他和imp类似
impdp system/password
directory=expdp dumpfile=back.dmp
remap_schema='usera':'userb' logfile=backlog.log
2、更改表空间
用exp/imp,想要更改表空间,需要手动处理,如alter table xxx move tablespace_new之类的操作,而是用impdp只要用:
remap_tablespace='tablespace_old' : 'tablespace_new'
3、当制定多个表的时候
exp/imp用法:tables('table1','table2','table3')
expdp/impdp用法:tables='table1','table2','table3'
4、是否要导出数据行
exp rows=y,导出数据行,rows=n不导出数据行
expdp content(all:对象+数据行,data_only:只导出对象,metadata_only:只导出数据的记录
资料来源:
https://www.cnblogs.com/zhengcheng/p/4201567.html
https://note.youdao.com/share/?id=bb8dd43350746e619a61d3c6d3e09c82&type=note#/