美文网首页数据库
Oracle以expdp/impdp方式数据迁移

Oracle以expdp/impdp方式数据迁移

作者: 纳米君 | 来源:发表于2019-12-05 23:16 被阅读0次

一、先确定两边库编码是否一致

select userenv('language') from dual;

二、进入命令行操作

su - oracle 切到oracle用户
sqlplus / as sysdba (找不到sqlplus命令时,使用`ln -s /u01/app/oracle/product/11.2/db_1/bin/sqlplus /usr/bin`)
create or replace directory expdp_dir as '/expdp';(创建directory对象,注意先创建目录/expdp,并设置权限777)
select * from dba_directories;(查看是否存在该目录,可省略)
grant read,write on directory expdp_dir to htzh; (读写权限授权给 htzh 用户)
exit 退出 sqlplus

三、数据泵导出指定用户数据(已退出sqlplus)

expdp htzh/a123456 schemas=htzh directory=expdp_dir dumpfile=htzh.dmp logfile=htzh.log compression=ALL parallel=4

htzh/a123456 账号/密码
schemas=htzh 库名
directory=expdp_dir 步骤二中设置的目录
dumpfile=htzh.dmp 导出文件名
logfile=htzh.log 导出日志文件名
compression=ALL压缩文件
parallel=4 并行,数值根据CPU核数而定

四、新机器上数据泵导入用户数据

4.1、先以sysdba登录,给账号dev授权(当前能登录的账号)

sqlplus / as sysdba
grant connect,resource,dba to dev;

4.2、创建表空间(语句从老库复制过来,可能需要更改dbf文件路径)

CREATE TABLESPACE "HTZH" DATAFILE 
  '/u01/app/oracle/oradata/orcl/sstir_member_temp02.dbf' SIZE 2097152000
  AUTOEXTEND ON NEXT 209715200 MAXSIZE 32767M,
  '/u01/app/oracle/oradata/orcl/htzh.dbf' SIZE 2097152000
  AUTOEXTEND ON NEXT 209715200 MAXSIZE 32767M
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT NOCOMPRESS  SEGMENT SPACE MANAGEMENT AUTO;
  
CREATE TEMPORARY TABLESPACE "HTZH_TEMP" TEMPFILE 
  '/u01/app/oracle/oradata/orcl/htzh_temp.dbf' SIZE 52428800
  AUTOEXTEND ON NEXT 52428800 MAXSIZE 20480M
  EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1048576;

4.3、创建用户(语句从老库复制过来)

CREATE USER "HTZH" IDENTIFIED BY VALUES 'S:EF75C51DCCC4FB7DE1FEDA72C8F654F827BC15C36744AD97ACF10F465629;ED2C0AC9C16F30B6'
      DEFAULT TABLESPACE "HTZH"
      TEMPORARY TABLESPACE "HTZH_TEMP";

4.4、给用户授权,

grant connect,resource,dba to HTZH;

4.5、进入命令行操作,重复步骤二

su - oracle
sqlplus / as sysdba
create or replace directory expdp_dir as '/expdp'; 
select * from dba_directories; 
grant read,write on directory expdp_dir to htzh; 
exit

4.6、开始导入到指定用户(已退出sqlplus)

impdp htzh/a123456 schemas=htzh directory=expdp_dir dumpfile=htzh.dmp logfile=htzh.log parallel=4

五、导出导入全部数据库,参数full=y(导入需要先建立表空间和用户)

expdp htzh/a123456 directory=expdp_dir dumpfile=full.dmp full=y compression=ALL parallel=4
impdp htzh/a123456 directory=expdp_dir dumpfile=full.dmp full=y parallel=4

相关文章

网友评论

    本文标题:Oracle以expdp/impdp方式数据迁移

    本文链接:https://www.haomeiwen.com/subject/tjgowctx.html