导入命令
imp 用户名/密码 file=/home/oracle/test.dmp full=y ignore=y
示例
imp system/system file=/home/oracle/20190917.dmp full=y ignore=y
# 备份文件目录 /home/oracle/app/oracle/admin/orcl/dpdump
# 采用数据泵方式导入,需要预先将dmp文件放置到指定的directory目录下,
# https://blog.csdn.net/pierre_/article/details/46346843
# 可通过以下命令查看数据库已有的目录:
select * from DBA_DIRECTORIES;
# 授权
grant read,write on directory DATA_PUMP_DIR to suplab;
# 如果导出采用的是expdp方式,则要使用impdp命令
impdp suplab/suplab file=SUPLAB20201014.DMP full=y ignore=y
执行结果
[oracle@58ef6fab3e67 ~]$ imp system/system file=/home/oracle/20190917.dmp full=y ignore=y
Import: Release 11.2.0.1.0 - Production on Mon Oct 28 11:53:23 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
....
....
....
importing CLINPATH's objects into CLINPATH
Import terminated successfully with warnings.
实战
现有一个通过 expdp
命令导出的Oracle数据库,名为:SUPLAB20201014.DMP
文件。
进入oracle
服务器,切换为oracle
用户
su - oracle
用户名密码为:system/system
[oracle@029bcb21ca45 ~]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 16 17:34:12 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter user-name:
# 创建表空间
SQL> create tablespace suplab datafile '/home/oracle/app/oracle/oradata/helowin/suplab.dbf' size 1024M autoextend on next 500M maxsize unlimited extent management local segment space management auto;
# 创建用户
SQL> create user suplab identified by suplab default tablespace suplab;
# 授权
SQL> grant connect to suplab;
SQL> grant resource to suplab;
SQL> grant create any view to suplab;
SQL> grant unlimited tablespace to suplab;
SQL> grant create job to suplab;
SQL> grant create synonym to suplab;
SQL> grant debug any procedure to suplab;
SQL> grant debug connect session to suplab;
SQL> grant create sequence,select any sequence to suplab;
SQL> grant read, write on directory DATA_PUMP_DIR to suplab;
SQL> grant dba to suplab;
查看DATA_PUMP_DIR
目录
SQL> select * from DBA_DIRECTORIES;
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS DATA_PUMP_DIR
/home/oracle/app/oracle/admin/orcl/dpdump/
将SUPLAB20201014.DMP
文件上传至服务器DATA_PUMP_DIR
目录下,确保文件权限用户组为oracle:oinstall
,如下
-rw-r--r-- 1 oracle oinstall 218738688 Oct 16 15:24 SUPLAB20201014.DMP
如果不是,则用root
用户授权
chown oracle:oinstall SUPLAB20201014.DMP
如果没有该目录,则创建
mkdir -p /home/oracle/app/oracle/admin/orcl/dpdump/
使用impdp
命令还原dmp
文件
impdp suplab/suplab file=SUPLAB20201014.DMP full=y ignore=y