早上看了一下《oracle从入门到精通》中数据的导入导出,这个之前在项目中经常用到,但是命令都是网上找的,并不了解其中的含义,现在刚好看到这,做了一些笔记
94.数据导出工具 expdp
expdp是服务器端工具,只能在服务器端使用,客户端可使用exp工具
expdp工具只能将导出的转储文件放在directory对象对应的目录,不能直接指定磁盘目录。因此使用expdp工具,首先建立directory对象,并且需要为数据库用户授予使用directory对象的权限
1)创建directory对象
create directory dump_dir as 'd:\dump';
2)授权
grant read,write on directory dump_dir to scott;
3)导出表
导出表是指将一个或多个表的结构及其数据存储到转储文件中。普通用户只能导出自身模式中的表。导出其他模式中的表,必须具有exp_full_database角色或dba角色权限。在导出表时,每次只能导出一个模式中的表
expdp scott/123456 directory=dump_dir dumpfile=tab.dmp tables=emp,dept //导出scott模式中的emp和dept表
4)导出模式
导出模式是指将一个或多个模式中的所有对象及数据转储到转储文件中,导出模式要求用户具有exp_full_database或dba角色权限
expdp system/123456 directory=dump_dir dumpfile=schema.dmp schemas=scott,hr
//导出scott模式和hr模式中的所有对象和数据
5)导出表空间
导出表空间是指将一个或多个表空间中的所有对象及数据转储到转储文件中。导出表空间必须有dba角色或exp_full—database角色
expdp system/123456 directory=dump_dir dumpfile=tablespace.dmp tablespaces=tbsp_1
//导出表空间tbsp_1
6)导出全数据库
导出全数据库是指将数据库中的所有对象及数据存储到转储文件中,导出数据库要求用户必须有dba角色或exp_full_database角色。注意:导出数据库时,不会导出sys,ordsys,ordplugins,ctxsys,mdsys,lbacsys以及xdb等模式中的对象
expdp system/123456 directory=dump_dir dumpfile=fulldatabase.dmp full=y
7)expdp命令参数
1.content 用户指定要导出的内容,默认值为all
content={all | data_only | metadata_only}
all: 将导出对象定义及其所有数据
data_only:只导出对象数据
metadata_only: 只导出对象定义
expdp scott/123456 directory=dump_dir dumpfile=content.dmp content=data_only
2.query 用于指定过滤导出数据的where条件
query=[schema.][table_name:] query_clause
schema: 用于指定模式名
table_name: 用于指定表名
query_clause:用于指定条件限制子句
query不能与connect=metadata_only,extimate_only,transprot_tablespaces等参数同时使用
expdp scott/123456 directory=dump_dir dumpfile=query.dmp tables=dept query='where deptno=10'
//导出dept表中编号为10的数据
3.directory 指定转储文件和日志文件所在的目录
4.dumpfile 指定转储文件的名称
5.full 指定数据库模式导出 默认为n
full={y | n}
当设置为y时,表示执行数据库导出
6.logfile 指定导出日志文件的名称,默认名称 export.log
7. status 导出作业进程的详细状态 默认为0
status=integer
8.tables 用于指定表模式导出
tables=[schema_name.]table_name[:partition_name][...]
schema_name:用于指定模式名
table_name:用于指定要导出的表名
partition_name:用于指定要导出的分区名
9.tablespaces 指定表空间列表
95.数据导入工具 impdp 数据泵
服务器端的工具,只能在oracle服务端使用,客户端可使用imp
1)导入表
impdp system/123456 directory=dump_dir dumpfile=tab.dmp tables=scott.dept,scott.emp remap_schema=scott:system
//将scott模式下的dept,emp表导入到system模式中,将表导入到其他模式中,必须指定remap_schema参数
2)导入模式
impdp system/123456 directory=dump_dir dumpfile=schema.dmp schemas=scott remap_schema=scott:system;
//将scott模式中的所有对象导入到system模式中
3)导入表空间
impdp system/123456 directory=dump_dir dumpfile=tablespace.dmp tablespaces=tbsp_1
//将tbsp_1表空间中的所有对象导入到当前数据库中
4)导入全数据库
impdp system/123456 directory=dump_dir dumpfie=fulldatabase.dmp full=y
从fulldatabase.dmp文件中导入全数据库
5)参数
remap_schema 用于将源模式中的对象转载到目标模式中。
remap_schema=source_schema:target_schema
source_schema:源模式
target_schema:目标模式
remap_tablespace
remap_tablespace=source_tablespace:target_tablespace
sqlfile 可以从dmp文件中提取对象的ddl语句,该参数用于将导入的ddl操作写入到sql脚本中
sqlfile=[directory_object:]file_name
file_name表示包含ddl语句的文件。实际上impdp只是从dmp文件中提取对象的ddl语句,这样impdp并不把数据导入数据库中,只是创建ddl语句文件
impdp scott/123456 directory=dump_dir dumpfile=sqlfile.dmp sqlfile=test.sql
table_exists_action 用于指定当前表已经存在时导入作业要执行的操作,默认skip
table_exists_action={skip | append | truncate | replace}
skip:导入作业会跳过已存在表,处理下一个对象
append:会追加数据
truncate:导入作业会截断表,然后为其追加新数据
replace:导入作业会删除已存在的表,然后重建表追加数据
transprort_datafiles 表示移动表空间时要被导入到目标数据库的数据文件。
transport_datafiles=datafile_name
datafile_name用于指定被复制到·目标数据库的数据文件
impdp system/123456 directory dump dumpfile=tran_datafiles.dmp transport_datafile='d:\test.dbf'
//向当前数据库导入test.dbf数据文件
更多推荐
oracle数据库导入导出工具
发布评论