导出:
EXP userid=<username>/<password>@<service_name> file=<dmpname>
e.g.
exp sams/sams@orcl file='d:\dbbak20130731.bak' grants=y full=y
exp sams/sams@EX205 file='e:\sams20130820.bak' grants=y full=y
导入:
IMP userid=<username>/<password>@<service_name> file=<dmpname> fromuser=<fromuser> touser=<touser>
e.g.
imp sams/sams@orcl file='e:\sams.dmp' fromuser=sams touser=sams
imp sams/sams@orcl file='e:\sams20130820.bak' fromuser=sams touser=sams ignore=y
impdb sams/sams@orcl DIRECTORY=dump_dir DUMPFILE='e:\sams20130820.bak' FULL=y table_exists_action=truncate;
1. drop user
drop user sams cascade
2. create user
-- Create the user
create user sams
identified by sams;
-- Grant/Revoke role privileges
grant dba to sams;
可以先drop user sams cascade;然后再创建用户进行导入。。。
如果使用impdp的话,可以添加table_exists_action参数
a.忽略(SKIP,默认行为);
b.在原有数据基础上继续增加(APPEND);
c.先DROP表,然后创建表,最后完成数据插入(REPLACE);
d.先TRUNCATE,再完成数据插入(TRUNCATE)
2.EXPDP用法举例:
1)按用户导
expdp scott/tiger@orcl
schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;
2)并行进程parallel
expdp scott/tiger@orcl directory=dpdata1 dumpfile=scott3.dmp parallel=40 job_name=scott3
3)按表名导
expdp scott/tiger@orcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dpdata1;
4)按查询条件导
expdp scott/tiger@orcl directory=dpdata1 dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20';
5)按表空间导
expdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=temp,example;
6)导整个数据库
expdp system/manager DIRECTORY=dpdata1 DUMPFILE=full.dmp FULL=y;
3.IMPDP用法举例:
1)导到指定用户下
impdp scott/tiger DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=scott;
2)改变表的owner
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
3)导入表空间
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=example;
4)导入数据库
impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;
5)追加数据
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION