Linux下Oracle新建用户并且将已有的数据dmp文件导入到新建的用户下的操作流程

Oracle新建用户并且将已有的数据dmp文件导入到新建的用户下的操作流程

1.切换到oracle用户下
su - oracle
2.登录sqlplus
sqlplus /nolog
3.使用sysdba登录
conn /as sysdba
4.查询表空间存储位置
select name from v$tempfile;
5、创建临时表空间
create temporary tablespace TMP_CAL tempfile '/home/oracle/tablespace/TMP_CAL_01.dbf' size 2G reuse autoextend on next 20m maxsize unlimited;
6、创建数据表空间
create tablespace DATA_AML_BUSI datafile '/home/oracle/tablespace/DATA_AML_BUSI_01.dbf' size 100M reuse autoextend on next 40M maxsize unlimited;
7、创建索引表空间
create tablespace IDX_BUSI logging datafile '/home/oracle/tablespace/INDEX_01.dbf' size 100m autoextend on next 32m maxsize 2048m extent management local;
8、创建用户并分配表空间
create user aml3 identified by aml3 default tablespace DATA_AML_BUSI temporary tablespace TMP_CAL;
9、赋权dba给用户
grant dba to aml3;
10、创建文件目录
create directory DATA_DIR as '/home/oracle/temp';
11、给用户赋文件目录的读写权限
grant read,write on directory dir to system;
1、导入dmp文件
方式一:同名同库同空间的
impdp aml/aml@orcl directory=DATA_DIR dumpfile=aml_v2.dmp
方式二:不同名,不同表空间,不同用户
 impdp aml3/aml3@orcl transform=segment_attributes:n directory=DATA_DIR dumpfile=aml_v2.dmp  remap_tablespace=DATA_BUSI:DATA_AML_BUSI remap_schema=aml:aml3   logfile=exdp.log;
----remap_tablespace=DATA_BUSI:DATA_AML_BUSI    将数据的tablespace 从a 转换为b
----remap_schema=aml:aml3                       将数据的schema从a 转换为b


/************************************************/
/            Oracle 常用操作指南                       /
/************************************************/
--1、查询原数据库信息
--1.1查询数据库实例名
select name from v$database;
--1.2查询数据库字符集
select * from nls_database_parameters t where t.PARAMETER='NLS_CHARACTERSET';
--1.4查询数据库中自己创建的用户
select * from all_users t order by t.created desc;
--1.5查询用户对应的表空间
select * from dba_users t where t.username ='AML';
--1.6查询临时表空间和表空间的存储位置
select * from user_tablespaces
select name from v$tempfile;
--1.7删除表空间
drop tablespace TMP_CAL including contents and datafiles;
--1.8查询文件目录位置
select * from dba_directories;
/************************************************/
/        Oracle 数据泵导入导出指南               /
/************************************************/
一、新建逻辑目录
以system等管理员创建逻辑目录,Oracle不会自动创建实际的物理目录“D:\oracleData”(务必手动创建此目录),仅仅是进行定义逻辑路径dump_dir;
sql>create directory dump_dir as 'D:\oracleData';
二、查看管理员目录(同时查看操作系统是否存在该目录,因为oracle并不关心该目录是否存在,假如不存在,则出错)
 sql>select * from dba_directories;
三、用expdp导出数据

1)导出用户及其对象
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=dump_dir;

2)导出指定表
expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=dump_dir;

3)按查询条件导
expdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp tables=empquery='where deptno=20';

4)按表空间导
expdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp    tablespaces=temp,example;

5)导整个数据库
expdp system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;

6)导出每个表里的20条数据
expdp ncms_yn/ncms_yn@yndw1  dumpfile=NCMS_YN.dmp DIRECTORY=EXPDP_DIR  QUERY=\"WHERE ROWNUM \<21\"


四、用impdp导入数据
 在正式导入数据前,要先确保要导入的用户已存在,如果没有存在,请先用下述命令进行新建用户
 
--创建表空间
create tablespace tb_name datafile 'D:\tablespace\tb_name.dbf' size 1024m AUTOEXTEND ON;

--创建用户
create user user_name identified by A123456a default tablespace tb_name temporary tablespace TEMP;

--给用户授权
sql>grant read,write on directory dump_dir to user_name;
sql>grant dba,resource,unlimited tablespace to user_name;

1)导入用户(从用户scott导入到用户scott)
impdp scott/tiger@orcl directory=dump_dir dumpfile=expdp.dmp schemas=scott;

2)导入表(从scott用户中把表dept和emp导入到system用户中)
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmptables=scott.dept,scott.emp remap_schema=scott:system;

3)导入表空间
impdp system/manager@orcl directory=dump_dir dumpfile=tablespace.dmp tablespaces=example;

4)导入数据库
impdb system/manager@orcl directory=dump_dir dumpfile=full.dmp full=y;

5)追加数据
impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action

 

posted @ 2020-09-25 10:50  阿宝叔  阅读(1229)  评论(0编辑  收藏  举报