【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: 解决表空间前后不一致的问题,前面:源表空间,后面:目标表空间

相关推荐
煮煮论英雄6 小时前
单文件部署的MQTT轻量级物联网数据平台
jvm·物联网·oracle
蓝鸟19746 小时前
Python Flask + Oracle 接口开发 小白完整版笔记(入参/查库/批量/JSON/避坑)
python·oracle·flask
2601_967338716 小时前
Text2SQL智能体基础到实战课程
数据库·oracle
祢真伟大7 小时前
Oracle含LOB大字段表的存储占用统计
数据库·oracle
严同学正在努力8 小时前
Oracle数据技术运维大全(下篇)
运维·数据库·ai·oracle·架构
Irene19919 小时前
FROM DUAL UNION ALL 是 Oracle 特有的写法,专门用来在 SQL 中手工构造一个固定的多行数据集(即“行值构造函数”)。
oracle·行值构造函数
cqsztech2 天前
Oracle ai database 26ai rac 通过gold image 更新季度补
数据库·人工智能·oracle
cqsztech2 天前
银河麒麟v11下 19c noncdb升级到 26ai
oracle
杨云龙UP2 天前
Oracle 19c RMAN历史备份清理失败:CONTROL_FILE_RECORD_KEEP_TIME 问题排查与整改实战
linux·运维·网络·数据库·oracle·rac
疯狂打码的少年2 天前
【数据库技术】SQL概述与数据定义(DDL:CREATE/DROP/ALTER)
数据库·笔记·sql·oracle