如何将dmp文件导入到Oracle
一、概述
在将dmp文件导入到Oracle中之前,需要先创建一个orcale用户。然后使用该用户名和密码,以imp的方式将数据导入到oracle中。
二、执行步骤
1、登陆oracle数据库
a、sqlplus / as sysdba
b、如果使用a不成功,则使用 sqlplus demo/demo@localhost/ORCLpdb1的方式
2、查询临时空间表和表空间的存储位置
select name from v$tempfile;
select name from v$datafile;
3、创建用户临时表空间和表空间,使用上面查到的任一存储位置即可
create temporary tablespace demo_temp tempfile '/oracle/u02/oradata/ERP2/demo_temp.dbf' size 100m reuse autoextend on next 20m maxsize unlimited;
create tablespace demo datafile '/oracle/u02/oradata/ERP2/demo.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
注:删除表空间的命令drop tablespace temp including contents and datafiles;
4、创建用户并指定表空间
create user demo identified by demo default tablespace demo temporary tablespace demo_temp;
5、如果此时报错,Oracle 19c:创建用户时出现“ORA-65096: invalid common user or role name”的错误
这时涉及到CDB和PDB的基本管理,资料来源oracle官方。
基本概念:
Multitenant Environment:多租户环境
CDB(Container Database):数据库容器
PD(Pluggable Database):可插拔数据库
CDB与PDB关系图
COMMON USERS(普通用户):经常建立在CDB层,用户名以C##或c##开头;
LOCAL USERS(本地用户):仅建立在PDB层,建立的时候得指定CONTAINER。
官方原始文件介绍如下:
The data dictionary in each container in a CDB is separate, and the current container is the container whose data dictionary is used for name resolution and for privilege authorization. The current container can be the root or a PDB. Each session has exactly one current container at any point in time, but it is possible for a session to switch from one container to another.
Each container has a unique ID and name in a CDB. You can use the CON_ID and CON_NAME parameters in the USERENV namespace to determine the current container ID and name with the SYS_CONTEXT function.
说白了,就是你当前的session不能创建你需要的用户,需要使用SYS_CONTEXT函数
a、查看Oracle 19c的版本
select * from v$version;
select sys_context ('USERENV', 'CON_NAME') from dual;
b、我们可以通过ALTER SESSION SET CONTAINER 指定其他容器
select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
C、将PDB open
alter pluggable database pdborcl open;
d、查看容器
select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
e、切换到pdb
alter session set container=PDBORCL;
f、查看当前使用容器
select sys_context ('USERENV', 'CON_NAME') from dual;
g、创建用户
create user demo identified by demo default tablespace demo temporary tablespace demo_temp;
6、导入文件到oracle
oracle连接方式用两种,一般用户喜欢使用Server_id的方式,导入方式为
imp demo/123456@orcl file="C:\Users\xiejiachen\Desktop\test20190630.DMP" full =y;
使用server_name的导入方式如下:
imp demo/123456@localhost/ORCLpdb1 file=home/oracle/demo.dmp ignore=y full=y
其中demo为用户名,123456为密码,@后面是主机名称,ORCLpdb1是server的名称。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)