当前位置:网站首页>oracle11g数据库导入导出方法教程[通俗易懂]
oracle11g数据库导入导出方法教程[通俗易懂]
2022-06-26 13:32:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
oracle11g数据库导入导出:
①:传统方式——exp(导出)和(imp)导入: ②:数据泵方式——expdp导出和(impdp)导入; ③:第三方工具——PL/sql Developer; 一、什么是数据库导入导出? oracle11g数据库的导入/导出,就是我们通常所说的oracle数据的还原/备份。 数据库导入:把.dmp 格式文件从本地导入到数据库服务器中(本地oracle测试数据库中); 数据库导出:把数据库服务器中的数据(本地oracle测试数据库中的数据),导出到本地生成.dmp格式文件。 .dmp 格式文件:就是oracle数据的文件格式(比如视频是.mp4 格式,音乐是.mp3 格式); 二、二者优缺点描述: 1.exp/imp: 优点:代码书写简单易懂,从本地即可直接导入,不用在服务器中操作,降低难度,减少服务器上的操作也就 保证了服务器上数据文件的安全性。 缺点:这种导入导出的速度相对较慢,合适数据库数据较少的时候。如果文件超过几个G,大众性能的电 脑,至少需要4~5个小时左右。 2.expdp/impdp: 优点:导入导出速度相对较快,几个G的数据文件一般在1~2小时左右。 缺点:代码相对不易理解,要想实现导入导出的操作,必须在服务器上创建逻辑目录(不是真正的目录)。我们 都知道数据库服务器的重要性,所以在上面的操作必须慎重。所以这种方式一般由专业的程序人员来完 成(不一定是DBA(数据库管理员)来干,中小公司可能没有DBA)。 3.PL/sql Develpoer: 优点:封装了导入导出命令,无需每次都手动输入命令。方便快捷,提高效率。 缺点:长时间应用会对其产生依赖,降低对代码执行原理的理解。 三、特别强调: 目标数据库:数据即将导入的数据库(一般是项目上正式数据库); 源数据库:数据导出的数据库(一般是项目上的测试数据库); 1.目标数据库要与源数据库有着名称相同的表空间。 2.目标数据在进行导入时,用户名尽量相同(这样保证用户的权限级别相同)。 3.目标数据库每次在进行数据导入前,应做好数据备份,以防数据丢失。 4.使用数据泵时,一定要现在服务器端建立可用的逻辑目录,并检查是否可用。 5.弄清是导入导出到相同版本还是不同版本(oracle10g版本与oracle11g版本)。 6.目标数据导入前,弄清楚是数据覆盖(替换),还是仅插入新数据或替换部分数据表。 7.确定目标数据库磁盘空间是否足够容纳新数据,是否需要扩充表空间。 8.导入导出时注意字符集是否相同,一般Oracle数据库的字符集只有一个,并且固定,一般不改变。 9.导出格式介绍: Dmp格式:.dmp是二进制文件,可跨平台,还能包含权限,效率好; Sql格式:.sql格式的文件,可用文本编辑器查看,通用性比较好,效率不如第一种, 适合小数据量导入导出。尤其注意的是表中不能有大字段 (blob,clob,long),如果有,会报错; Pde格式:.pde格式的文件,.pde为PL/SQL Developer自有的文件格式,只能用PL/SQL Developer工具 导入导出,不能用文本编辑器查看; 10.确定操作者的账号权限。 四、二者的导入导出方法: 1、传统方法: 通用命令:exp(imp) username/[email protected]:1521 file=”e:\temp.dmp” full = y; 数据库导出举例:
exp xinxiaoyong/[email protected]:1521 file=”e:\temp.dmp” full = y;
exp:导出命令,导出时必写。 imp:导入命令,导入时必写,每次操作,二者只能选择一个执行。 username:导出数据的用户名,必写; password:导出数据的密码,必写; @:地址符号,必写; SERVICENAME:Oracle的服务名,必写; 1521:端口号,1521是默认的可以不写,非默认要写; file=”e:\temp.dmp” : 文件存放路径地址,必写; full=y :表示全库导出。可以不写,则默认为no,则只导出用户下的对象; 方法细分: 1.完全导入导出: exp(imp) username/[email protected]:1521 file=”e:\temp.dmp” full = y; 2.部分用户表table导入导出: exp(imp) username/[email protected]:1521 file=”e:\temp.dmp” tabels= (table1,table2,table3,…); 3.表空间tablespaces导入导出: //一个数据库实例可以有N个表空间(tablespace),一个表空间下可以有N张表(table)。 exp(imp) username/[email protected]:1521 file=”e:\temp.dmp” tablespaces= (tablespace1,tablespace2,tablespace3,…); 4.用户名username对象导入导出: exp(imp) username/[email protected]:1521 file=”e:\temp.dmp” owner(username1,username2,username3); 2、数据泵方法: 创建directory: expdp(impdp) username/[email protected]:1521 schemas=username dumpfile=file1.dmp logfile=file1.log directory=testdata1 remap_schema=test:test; 数据库导出举例: expdp xinxiaoyong/[email protected]:1521 schemas=xinxiaoyong dumpfile=test.dmp logfile=test.log directory=testdata1;
exp:导出命令,导出时必写。 imp:导入命令,导入时必写,每次操作,二者只能选择一个执行。 username:导出数据的用户名,必写; password:导出数据的密码,必写; @:地址符号,必写; SERVICENAME:Oracle的服务名,必写; 1521:端口号,1521是默认的可以不写,非默认要写; schemas:导出操作的用户名; dumpfile:导出的文件; logfile:导出的日志文件,可以不写; directory:创建的文件夹名称; remap_schema=源数据库用户名:目标数据库用户名,二者不同时必写,相同可以省略; 1.查看表空间: select * from dba_tablespaces; 2.查看管理理员目录(同时查看操作系统是否存在,因为Oracle并不关心该目录是否存在,如果不存 在,则出错)。 select * from dba_directories; 3.创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建。 create directory testdata1 as ‘d:\test\dump’; 4.给xinxiaoyong用户赋予在指定目录的操作权限,最好以system等管理员赋予。 //xinxiaoyong 是用户名(123456是用户密码) grant read,write on directory testdata1 to xinxiaoyong; 5.导出数据
1)按用户导 expdp xinxiaoyong/[email protected] schemas=xinxiaoyong dumpfile=expdp.dmp directory=testdata1;
2)并行进程parallel expdp xinxiaoyong/[email protected] directory=testdata1 dumpfile=xinxiaoyong3.dmp parallel=40 job_name=xinxiaoyong3 3)按表名导 expdp xinxiaoyong/[email protected] tables=emp,dept dumpfile=expdp.dmp directory=testdata1; 4)按查询条件导 expdp xinxiaoyong/[email protected] directory=testdata1 dumpfile=expdp.dmp tables=emp query=’WHERE deptno=20′; 5)按表空间导 expdp system/manager directory=testdata1 dumpfile=tablespace.dmp tablespaces=temp,example; 6)导整个数据库 expdp system/manager directory=testdata1 dumpfile=full.dmp FULL=y; 6.还原数据 1)导到指定用户下 impdp xinxiaoyong/123456 directory=testdata1 dumpfile=expdp.dmp schemas=xinxiaoyong; 2)改变表的owner impdp system/manager directory=testdata1 dumpfile=expdp.dmp tables=xinxiaoyong.dept remap_schema =xinxiaoyong:system; 3)导入表空间 impdp system/manager directory=testdata1 dumpfile=tablespace.dmp tablespaces=example; 4)导入数据库 impdb system/manager directory=dump_dir dumpfile=full.dmp FULL=y; 5)追加数据 impdp system/manager directory=testdata1 dumpfile=expdp.dmp schemas=system table_exists_action; 3、PLSQL方法: 登录plsql工具,所使用用户为源数据库有导出权限(exp_full_database,dba等)的用户。 1.导出建表语句(包括存储结构)
导出步骤tools ->export user object,选择要导出的对象,导出.sql格式文件并等待导出完成,如 下图:
导出数据文件 ; 2.导出步骤tools ->export tables,选择要导出的表及导出的格式进行导出。
导出为dmp格式,如下图:
导出为sql格式,如下图:
导出为pde格式,如下图:
提示说明:采用第三方工具导出导入整个数据库的话,耗时较长,一定要有足够
的时间来操作(数据量大的话需要好几个小时)。
3.导入建表语句 导入步骤tools->import tables->SQL Inserts 导入.sql文件 4.导入数据; tools->import talbes,然后再根据导出的数据格式选择导入dmp文件,或者sql文件, 或者pde文件。 提示说明:导入之前最好把以前的表删除,当然导入另外数据库除外。 另外导入时当发现进度条一直卡在一个点,而且导出的文件不再增大时,甚至是提示程序 未响应,千万不要以为程序卡死了,这个导入导出就是比较缓慢,只要没有提示报错,
或者导入完成就不要停止程序。
提示:创建数据库,表空间这里略过,本文主要讨论数据的导入导出,如果对此感觉稍有遗漏,尽请见谅。由于水平有限,本文档仅提供参考。如代码有错误之处,请见谅。如果有更好的开发经验,感谢回复。谢谢观看!!!;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/133822.html原文链接:https://javaforall.cn
边栏推荐
- Gartner 2022年顶级战略技术趋势报告
- Common controls and custom controls
- DOS command
- Common evaluation indexes of classification model -- confusion matrix and ROC curve
- Setup instance of layout manager login interface
- Half search, character array definition, character array uses D11
- RISC-V 芯片架构新规范
- datasets Dataset类(2)
- Sword finger offer 21.57.58 I Double pointer (simple)
- A must for programmers, an artifact utools that can improve your work efficiency n times
猜你喜欢

Sword finger offer 09.30 Stack

hands-on-data-analysis 第三单元 模型搭建和评估

Leaflet load day map

Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)

Practice with the topic of bit operation force deduction

Never use redis expired monitoring to implement scheduled tasks!

Hard (magnetic) disk (II)

Codeforces Global Round 21A~D

程序员必备,一款让你提高工作效率N倍的神器uTools

Gartner 2022年顶级战略技术趋势报告
随机推荐
Matlab programming related knowledge
Mathematical design D12 according to string function
array
How to check if a text field is empty or not in swift
Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
GEE——全球人类居住区网格数据 1975-1990-2000-2014
Codeforces Round #765 (Div. 2) D. Binary Spiders
Common controls and custom controls
Exercises under insect STL string
Sword finger offer 06.24.35 Linked list
Assert and constd13
transformers DataCollatorWithPadding类
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
CVPR 2022文档图像分析与识别相关论文26篇汇集简介
Installation and uninstallation of MySQL software for windows
Hands on data analysis unit 3 model building and evaluation
Codeforces Global Round 21A~D
Luogu p4513 xiaobaiguang Park
Sword finger offer 40.41 Sort (medium)
虫子 运算符重载的一个好玩的