oracle数据备份expdp/impdp和exp/imp

create tablespace 表空间名
datafile 'D:\表空间名'
size 50M
autoextend on
next 10M;

create user 用户名
identified by 密码
default tablespace 表空间名

grant dba to 用户名

--
数据泵导入导出expdp/impdp(按用户导出导入) create directory dpbak as 'D:/data/dpbak';--创建备份文件存放目录(dpbak为逻辑目录,指向所建物理路径) grant read,write on directory dpbak to public;--授予备份文件所在目录访问权限(public可改为指定用户名) su - oracle sqlplus / as sysdba drop user 用户名 cascade;--删除用户相关数据

--删除用户相关数据有时会遇到 ORA-01940: cannot drop a user that is currently connected 
解决办法:SELECT SID,SERIAL#,STATUS FROM V$SESSION WHERE USERNAME='用户名(大写)';
SID    SERIAL# STATUS
---- ------- ------
276 26658   KILLED
296 54514   INACTIVE
删除用户进程(删除后查看还会在,但是状态已经是杀掉了的,全部删完即可删除用户):
批量生成删除会话语句: select 'alter system kill session '''||sid||','||serial#||''';' from v$session where username = '用户名' and STATUS != 'KILLED';
ALTER  SYSTEM  KILL SESSION '276,26658';
ALTER  SYSTEM  KILL SESSION '296,54514';

--导出语句(logfile为导出日志)没用禁用sysdba登录时导出语句(用户名/密码)可替换为\"/ as sysdba\"
--高版本oracle导出时可以加version指定导出的版本 expdp 用户名/密码 directory=dpbak schemas=用户名 dumpfile=szpt_dp_20190806.dmp logfile=szpt_dp_20190806.log --导入语句 impdp \"/ as sysdba\" directory=dpbak schemas=用户名 dumpfile=szpt_dp_20190806.dmp logfile=szpt_dp_20190806.log --普通导入导出exp/imp select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null; --查询空表语句处理语句 exp 用户名/密码@127.0.0.1:1521/ORCL file=/usr/rdsys/oracle/20190228.dmp imp 用户名/密码@127.0.0.1:1521/ORCL file=E:\20190314_1.dmp full=Y
posted @ 2019-08-07 11:51  lost_s  阅读(419)  评论(0编辑  收藏  举报