数据库impdp

数据库impdp,第1张

写法跟expdp命令一样 如导出命令: expdp 用户名/密码  schemas=用户名 directory=exp dumpfile=*.dmp logfile=exp.log

导入命令只需把expdp换成impdp就行 impdp 用户名/密码  schemas=用户名 directory=exp dumpfile=*.dmp logfile=imp.log

注意事项:

首先从导出的机器中传到要导入数据库的机器上,如Windows可以放在D:\imp 文件夹下(如果两台机器 *** 作系统不同,需使用二进制传输dmp文件)

在要导入数据的数据库创建导入导出目录

SQL>create directory as 'D:\imp'

3.命令行中开始导入  impdp 用户名/密码  schemas=用户名 directory=exp dumpfile=*.dmp logfile=exp.log

导入格式(按用户方式导入,oracle在本机)

impdp 用户名/密码

schemas=要导入的用户(即是使用expdp导出的用户) directory=创建的文件夹名称(directory_name)

dumpfile=test.dmp(要放入到directory_path路径下) logfile=imp.log(可以不写)

[sql] view plain copy

--导入时必须先创建文件夹路径

create or replace directory bao as 'd:\oracle\test'

--给使用的用户授权(读写权限)

Grant read,write on directory bao to scott

--查看目录及权限

SELECT privilege, directory_name, DIRECTORY_PATH FROM user_tab_privs t, all_directories d

WHERE t.table_name(+) = d.directory_name ORDER BY 2, 1

创建完文件夹后,在win7下是没有创建的文件夹的,需要手动创建文件夹,并且把使用expdp导出的dmp文件放入该文件夹下(开始自己导入时,创建完文件夹后始终在磁盘上找不到)

期间报过好多错,像org-29283,org-06512,ora-29283,ora-39002,org-39070等等,反正很郁闷的~!

创建好文件夹后,进行导入:(我使用的是通过运行command命令进入命令行界面导入)

impdp scott/tiger schemas=certification directory=test dumpfile=test.dmp

这要导入后会报错,提示表空间XXX不存在,用户certification不存在

根据错误信息,创建好表空间,和用户,并设置用户的表空间

[sql] view plain copy

CREATE TABLESPACE TEACHER

LOGGING

DATAFILE 'D:\ORACLE\ORADATA\ORCL\TEACHER.DBF'

SIZE 1024M

AUTOEXTEND ON

NEXT 32M MAXSIZE 2048M

EXTENT MANAGEMENT LOCAL

drop user certification

create user certification identified by cert

DEFAULT TABLESPACE TEACHER

grant connect,resource to certification

grant create session,dba to certification

数据库导出(expdp)

使用sys或system账号登录oracle

通过"Window + R" 打开dos命令行界面,使用sys或system登录oracle。格式:sqlplus sys/密码@数据库实例名 as sysdba

2、创建逻辑目录 : create or replace directory data_dir as 'E:\orcl\data'

data_dir为路径名称,可自命名,E:\orcl\data为数据库导出文件存放路径(路径必须存在);

创建备份逻辑目录,此目录不是真实的目录,此目录需要手动在数据库服务端创建。

通过 select * from dba_directories 可以查看所有的目录.

3、为用户授予访问数据目录的权限,输入命令:Grant read,write on directory data_dir to dbuser

dbuser为数据库用户名(与第4步中相同)

4、导入导出 *** 作授权,输入命令:grant exp_full_database,imp_full_database to dbuser

5、退出,输入命令:exit

6、数据导出,执行命令:

expdp dbuser/123456@orcl schemas=dbuser dumpfile=expdp.dmp directory=data_dir logfile=expdp.log

注意:命令结束不需要加“”

expdp [为用户名]/[密码]@[服务名]

schemas=[为用户名]

dumpfile=[导出数据库文件(可自命名)]

directory=[目录名]

logfile=[日志文件文件名(可自命名)]

数据库还原前准备

1、创建表空间

复制代码

create tablespace tbs_dbsunny datafile

'D:\app\Sunny\oradata\TableSpace\tbs_dbsunny.DBF' size 1G

autoextend on next 100M maxsize unlimited logging

extent management local autoallocate

segment space management auto

复制代码

2、创建临时表空间

create temporary tablespace tbs_dnsunny_temp tempfile 'D:\app\Sunny\oradata\TableSpace\tbs_dnsunny_temp.DBF' size 1000M autoextend on next 100M maxsize unlimited

3、创建用户

create user sunny identified by sunny123 DEFAULT TABLESPACE tbs_dbsunny TEMPORARY TABLESPACE tbs_dnsunny_temp

4、授权

复制代码

alter user sunny temporary tablespace tbs_dnsunny_temp

ALTER USER sunny QUOTA UNLIMITED ON TBS_DBSUNNY

grant connect to sunny

grant resource to sunny

grant dba to sunny

grant create trigger to sunny

grant create session to sunny

grant create sequence to sunny

grant create synonym to sunny

grant create table to sunny

grant create view to sunny

grant create procedure to sunny

grant alter session to sunny

grant execute on ctxsys.ctx_ddl to sunny

grant create job to sunny

grant sysdba to sunny

alter user sunny default role all

-- 删除这个用户以及这个用户下的所有对象

DROP USER sunny CASCADE

复制代码

数据库导入(impdp)

1、使用sys或system 登录

通过"Window + R" 打开dos命令行界面,使用sys或system登录oracle。格式:sqlplus sys/密码@数据库实例名 as sysdba

sqlplus sys/12345@dborcl as sysdba

2、创建逻辑目录,并手动创建真实目录,并将备份文件DMP,放进此目录下

sqlplus create or replace directory data_dir as 'E:\orcl\data'

3、给目标用户授权

sqlplus grant read,write on directory data_dir to sunny

4、导入:在dos命令行,执行

注意 : impdp 语句 后面 不要加 " "

impdp sunny/sunny123@DBSUNNY directory=data_dir dumpfile=EXPDPBUDGET.DMP logfile=impbudgett.log remap_schema =budgett:sunny remap_tablespace=PIMS:TBS_DBSUNNY

注:remap_schema=olduser:newuser 表示把左边的olduser用户的数据,导入到右边的newuser 用户里面

remap_tablespace=old_tbs:new_tbs 表示把将要导入的备份库的表空间old_tbs,导入到新库替换为 new_tbs

expdp导出数据

语法: expdp 用户名/密码@ip地址/实例 .... ip地址不写默认就是本地

复制代码

属性说明:

userid=test/test--导出的用户,本地用户!!

directory=dmpfile --导出的逻辑目录,一定要在oracle中创建完成的,并且给用户授权读写权限

dumpfile=xx.dmp --导出的数据文件的名称,如果想在指定的位置的话可以写成dumpfile=/home/oracle/userxx.dmp

logfile=xx.log --日志文件,如果不写这个参数的话默认名称就是export.log,可以在本地的文件夹中找到

schemas=userxx --使用dblink导出的用户不是本地的用户,需要加上schema来确定导出的用户,类似于exp中的owner,但还有一定的区别

EXCLUDE=TABLE:"IN('T1','T2','T3')" --exclude 可以指定不导出的东西,table,index等,后面加上不想导出的表名

network_link=db_local --这个参数是使用的dblink来远程导出,需要指定dblink的名称

复制代码

列出一些场景:

复制代码

1)导出用户及其对象

expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir logfile=expdp.log

2)导出指定表

expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir logfile=expdp.log

3)按查询条件导

expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20' logfile=expdp.log

4)按表空间导

expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=temp,example logfile=expdp.log

5)导整个数据库

expdp scott/[email protected]/orcl directory=dump_dir dumpfile=ly.dmp full=y logfile=expdp.log

复制代码

一般用的都是导出整个数据库,本人使用的代码:

//包含所有用户的表、视图、索引等

expdp JCPT/[email protected]/orcl directory=mydata dumpfile=ly.dmp full=y logfile=expdp.log

//指定用户的表、视图、索引等

expdp JCPT/[email protected]/orcl directory=mydata schemas=jcpt dumpfile=ly.dmp logfile=expdp.log

impdp 导入

列出一些场景:

复制代码

1)导入用户(从用户scott导入到用户scott)

impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott logfile=impdp.log

2)导入表(从scott用户中把表dept和emp导入到system用户中)

impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system logfile=impdp.log table_exists_action=replace (表空间已存在则替换)

3)导入表空间

impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example logfile=impdp.log

4)导入整个数据库

impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y logfile=impdp.log

5)追加数据

impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action logfile=impdp.log

复制代码

日常使用的:

//把用户jcpt中所有的表导入到lyxt用户下

impdp lyxt/[email protected]/orcl directory=mydata dumpfile=LY.DMP remap_schema=jcpt:lyxt logfile=ims20171122.log table_exists_action=replace


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10827734.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存