【Oracle】 Dump数据导出

1.Oracle dump

新建导出目录

[root@mldb002 oracle]# mkdir /u03/oracle/dump/
[root@mldb002 oracle]# chown -R oracle:oinstall /u03/oracle/dump
[root@mldb002 oracle]# ll
total 4
drwxr-xr-x 2 oracle oinstall 4096 Aug 17 11:01 dump
[root@oraclesit oracle]# su - oracle
[oracle@oraclesit ~]$ 

Oracle中创建导出目录

[oracle@oraclesit ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Aug 17 11:05:15 2018
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE DIRECTORY dump_dir AS '/u03/oracle/dump/'; --存放dmp、log文件
SQL> GRANT READ, WRITE ON DIRECTORY dump_dir TO root;     
SQL> exit;

数据导出

  • 全库导出

DIRECTORY:导出目录别名
DUMPFILE:导出文件
LOGFILE:导出日志
FULL=Y:是否全库导出
userName:passWord:具有数据导出权限的用户名和密码

[oracle@oraclesit ~]$ expdp userName/passWord DIRECTORY=dump_dir DUMPFILE=test20180817.dmp LOGFILE=test20180817.log FULL=Y
  • 指定用户导出

SCHEMAS=用户(所有可操作表等)

[oracle@oraclesit ~]$ expdp userName/passWord  DIRECTORY=dump_dir  DUMPFILE=test20180817.dmp LOGFILE=test20180817.log SCHEMAS=ml01usr  
[oracle@oraclesit dump]$ ll
总用量 94880
-rw-r-----. 1 oracle oinstall 97136640 8月  17 11:23 test20180817.dmp
-rw-r--r--. 1 oracle oinstall    15988 8月  17 11:23 test20180817.log

数据导入

impdp userName/passWord DIRECTORY=dump_dir DUMPFILE=test20180817.dmp LOGFILE=test20180817.log SCHEMAS=ml01usr

创建用户

数据的导入导出都需要使用有数据操作权限的用户
https://www.cnblogs.com/gzggyy/p/3319315.html

创建表空间
create temporary tablespace mldb_temp tempfile '/u01/app/oracle/oradata/mlerpdb01/mldb_temp.dbf' size 100m reuse autoextend on next 20m maxsize unlimited;  

create tablespace MLDB_DATA datafile '/u01/app/oracle/oradata/mlerpdb01/mldb_data.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

create tablespace MLDB_INDEX datafile '/u01/app/oracle/oradata/mlerpdb01/mldb_index.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

创建用户
[oracle@oraclesit dump]$ sqlplus / as sysdba
create user ml01usr identified by "passWord" default tablespace MLDB_DATA temporary tablespace mldb_temp;
grant connect,resource to ml01usr;
grant select any table to ml01usr;
grant delete any table to ml01usr;
grant update any table to ml01usr;
grant insert any table to ml01usr;

create user root identified by "passWord" default tablespace MLDB_DATA temporary tablespace mldb_temp;
grant dba to root;
grant connect,resource to root;
grant select any table to root;
grant delete any table to root;
grant update any table to root;
grant insert any table to root;

删除表空间
drop tablespace mldb_temp including contents and datafiles; 
drop tablespace MLDB_DATA including contents and datafiles; 
drop tablespace MLDB_INDEX including contents and datafiles; 

删除用户以及表数据
drop user ml01usr cascade

2.navicat 数据导入导出

使用命令适合一些定时或者周期性的数据导入导出,如:数据备份;命令行操作会比较繁琐,Navicat Oracle的mac版本也是支持数据迁移的。

1.Data Transfer

image.png

配置好源数据库连接和目的地数据库连接


image.png

选择需要迁移的表


image.png

点击下一步就可以开始数据迁移
image.png

创建表时会报如下错误:'no privileges on tablespace 'USERS'
原因在于users表空间中没有为bryan用户提供配额空间(在此默认的表空间为users)
有两种解决方案:
1.为用户在users表空间上设置合适的配额
SQL> alter user bryan quota 4M on users; //quota:配额,限额
2.为用户在users表空间上设置合适的配额
SQL> GRANT UNLIMITED TABLESPACE TO ml01usr;

2.Navicat可视化Dump

使用这个工具就能在界面上直接导入、导出dump文件


image.png
image.png

dump详细资料
Oracle数据泵

推荐阅读更多精彩内容