1.expdp导出相关
#sqlplus / as sysdba 创建逻辑目录、查看逻辑目录 SQL>create directory mydata as '/u01/mydata'; SQL>select * from dba_directories; 导出t1表 #su - oracle 1)导出用户及其对象 expdp hbhe/wwwwww@PDB01 schemas=scott dumpfile=expdp.dmp directory=dump_dir logfile=expdp.log; 2)导出指定表 expdp hbhe/wwwwww@PDB01 dumpfile=20200810.dmp directory=mydata tables=t1 logfile=expdp_t1.log; 3)按查询条件导 expdp hbhe/wwwwww@PDB01 directory=mydata dumpfile=expdp.dmp tables=empquery='where deptno=20' logfile=expdp.log; 4)按表空间导 expdp hbhe/wwwwww@PDB01 directory=mydata dumpfile=tablespace.dmp tablespaces=temp,example logfile=expdp.log; 5)导整个数据库 expdp hbhe/wwwwww@PDB01 directory=mydata dumpfile=ly.dmp full=y logfile=expdp_all_database.log; //包含所有用户的表、视图、索引等 expdp hbhe/wwwwww@PDB01 directory=mydata dumpfile=ly.dmp full=y logfile=expdp.log; //指定用户的表、视图、索引等 expdp hbhe/wwwwww@PDB01 directory=mydata schemas=jcpt dumpfile=ly.dmp logfile=expdp.log;
2.impdp导入相关
在正式导入数据前,要先确保要导入的用户已存在,如果没有存在,请先用下述命令进行新建用户 创建表空间-->创建用户并授权--->impdp导入数据 1. 创建表空间 使用system登录oracle,执行sql 格式: create tablespace 表间名 datafile '数据文件名' size 表空间大小 1. create tablespace data_test datafile '/u01/oracle/oradata/test/test.dbf' size 2000M; 2. (*数据文件名 包含全路径, 表空间大小 2000M 表是 2000兆) 2. 创建用户并授权 create user study identified by study default tablespace data_test; (*我们创建一个用户名为 study,密码为 study, 表空间为 madate-这是在上一步建好的.) 授权给 用户 study ,执行sql 1. #给用户逻辑目录读写权限 2. sql>grant read,write on directory mydata to study; 3. #给用户表空间权限 4. sql>grant dba,resource,unlimited tablespace to study; 3. impdp导入数据 命令在cmd或者控制台输入,不是sql语句 写法: impdp 用户名/密码@ip地址/实例 [属性] ip地址不写默认就是本地 注释: 1)导入用户(从用户scott导入到用户scott) impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott logfile=impdp.log; 2)导入表(从scott用户中把表dept和emp导入到system用户中) impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system logfile=impdp.log table_exists_action=replace (表空间已存在则替换); 3)导入表空间 impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example logfile=impdp.log; 4)导入整个数据库 impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y logfile=impdp.log; 日常使用的: 把用户HBHE中所有的表导入到hbhe用户下 impdp hbhe/wwwwww@PDB01 directory=mydata dumpfile=LY.DMP remap_schema=jcpt:lyxt logfile=ims20171122.log table_exists_action=replace 5)追加数据 impdp hbhe/wwwwww@PDB01 directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action logfile=impdp.lo



