一、导出数据库
1、exp方式
打开cmd,输入命令。
--简略
cmd> exp test(用户名)/123456(密码) file=D:\test.dmp owner=用户名
--完整
cmd> exp test(用户名)/123456(密码)@127.0.0.1(ip地址):1521(端口号)/orcl file=D:\test.dmp owner=用户名
2、expdp方式
打开cmd,输入命令。
cmd> expdp test(用户名)/123456(密码) directory=dmp_dir dumpfile=test.dmp full=y;
二、导入前准备
1、创建表空间
create tablespace test datafile 'D:\app\oracle\test.dbf' size 1024m autoextend on next 50m maxsize 31G;
2、创建用户
create user test(用户名) identified by 123456(密码) default tablespace test(表空间名) temporary tablespace TEMP(临时表空间名);
3、用户授权
grant connect,resource,dba to test(用户名);
三、导入数据库
1、imp导入
cmd> imp test(用户名)/123456(密码) file=D:\test.dmp full=y;
2、impdp导入
<!-- remap_schema:该参数用于将源模式中的所有对象转载到目标模式中,语法为:remap_schema=source_schema:target_schema -->
<!-- remap_tablespace:该参数用于指定导入时更改表空间名称,语法为:remap_tablespace=source_tablespace:target_tablespace -->
<!-- 当模式和表空间一致时,可不写 -->
cmd> impdp test(用户名)/123456(密码) directory=dump_dir dumpfile=D:\test.dmp remap_schema=test1:test remap_tablespace=test1:test full=y;
【补充】exp/imp 不导出空表的解决方案
查询空表生成sql语句,复制结果执行即可。
sql> select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows IS NULL;