【oracle】oracle基于数据泵方式进行数据迁移

下面以windows下oracle操作为例

1. 使用数据泵备份

  • 在D盘创建目录yn作为备份后的保存的的文件夹

  • 使用dba用户在oracle服务器上登录sqlplus sqlplus sys/sys@orcl as sysdba

  • 在sys登录后的sql命令行中创建导出目录对象create or replace directory exp_dir as 'D:\yn\';

  • 授权指定用户具有访问目录的权限

    sql 复制代码
    -- 授予目录读写权限
    grant read,write on directory exp_dir to test_user; 
    -- 授予数据泵操作权限
    grant exp_full_database to test_user;
    -- 预防用户权限不足
    grant dba to test_user; 
  • 导出操作(在服务器terminal中执行)

shell 复制代码
expdp test_user/test_user_pass@orcl 
 directory=exp_dir 
 dumpfile=exp_user_20260211.dmp 
 logfile=exp_user_20260211.log

命令中各字段说明如下

test_user:登录用户

test_user_pass:登录用户的密码

orcl:当前用户的 schema

exp_dir:前面设置的导出目录名称

dumpfile:导出的dmp文件名称

logfile:本次导出操作的日志

2. 使用数据泵还原

  • 在D盘创建目录yn作为导入时的保存数据的的文件夹,并将数据复制到这个文件夹下

  • 使用dba用户在oracle服务器上登录sqlplus sqlplus sys/sys@orcl as sysdba

  • 在sys登录后的sql命令行中创建导入目录对象create or replace directory imp_dir as 'D:\yn\';

  • 授权指定用户具有访问目录的权限

    sql 复制代码
    -- 授予目录读写权限
    grant read,write on directory imp_dir to test_user; 
    -- 授予数据泵操作权限
    grant imp_full_database to test_user;
    -- 预防用户权限不足
    grant dba to test_user; 
  • 导入操作(在服务器terminal中执行)

shell 复制代码
impdp test_user1/test_user_pass@orcl2 
 directory=imp_dir 
 dumpfile=exp_user_20260211.dmp 
 logfile=imp_user_20260211.log
 remap_schema=test_user:test_user1  
 remap_tablespace=orcl1:orcl2

命令中各字段说明如下

test_user1:登录用户

test_user_pass:登录用户的密码

orcl2:当前用户的 schema

imp_dir:前面设置的导入目录名称

dumpfile:待导入的dmp文件名称

logfile:本次导入操作的日志 remap_schema:解决映射前后用户不一致的问题,前面为:源库用户,后面为:待导入库的用户

remap_tablespace: 解决表空间前后不一致的问题,前面:源表空间,后面:目标表空间

相关推荐
jnrjian7 天前
ORA-01017 查找机器名 用户名 以及library cache lock 参数含义
数据库·oracle
TTc_7 天前
oracle中的union和union all有什么区别?
数据库·oracle
山峰哥7 天前
吃透 SQL 优化:告别慢查询,解锁数据库高性能
服务器·数据库·sql·oracle·性能优化·编辑器
南 阳8 天前
Python从入门到精通day37
数据库·python·oracle
轩情吖8 天前
MySQL库的操作
android·数据库·mysql·oracle·字符集·数据库操作·编码集
脱发的老袁8 天前
【数据库】Oracle手动清理归档日志
数据库·oracle
jnrjian8 天前
Oracle 共享池 库缓存下的 Library Cache Lock
数据库·缓存·oracle
新缸中之脑8 天前
在Reddit上探索未满足的需求
数据库·oracle
light blue bird8 天前
产线多并发客户端指令操作场景组件
jvm·oracle·.net·winform
坐吃山猪9 天前
Neo4j04_数据库事务
数据库·oracle·neo4j