- 1. 忘记oracle的sys或者system密码
- 2. 备份
- 2.1 分类
- 2.2 逻辑备份
- 2.2.1 expdp/impdp和exp/imp的区别
- 2.3 expdp 备份数据
- 2.4 导入
sqlplus /nolog >conn /as sysdba >alter user sys identified by 123456 #修改密码为1234562. 备份 2.1 分类
从物理与逻辑的,备份可以分为物理备份和逻辑备份。
-
物理备份(关闭数据库):对数据库操作系统的物理文件(数据文件,控制文件和日志文件)的备份,脱机备份(冷备份)和联机备份(热备份),使用oracle的恢复管理器(RMAN)或操作系统命令进行数据库的物理备份。
-
逻辑备份:对数据库逻辑组件(如表和存储过程等数据库对象)的备份。逻辑备份的手段很多,如传统的EXP,数据泵(EXPDP),数据库闪回技术等第三方工具,都可以进行数据库的逻辑备份。
- exp和imp是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。
- expdp和impdp是服务端的工具程序,他们只能在oracle服务端使用,不能在客户端使用。
- imp只适用于exp导出的文件,不适用于expdp导出文件;impdp只适用于expdp导出的文件,而不适用于exp导出文件。
- 对于10g以上的服务器,使用exp通常不能导出0行数据的空表,而此时必须使用expdp导出。
- 创建备份目录 F:ORACLE_BCK
- 用管理员身份登录到sqlplus
sqlplys /nolog SQL> conn sys/oracle as sysdba
- 创建逻辑目录 data_dir
SQL> create directory data_dir as 'F:ORACLE_BCK';
- 查询当前directory目录权限所有文件名和路径select * from dba_direcories;或者 select * from all_directories;
select * from all_directories where directory_name = 'DATA_DIR '; drop directory data_dir ;
- 赋予在该目录的操作权限
SQL> grant read,write on directory data_dir to sys;
- 备份
//1. “full=y”,全量导出数据库 expdp sys/oracle@orcl dumpfile=expdp.dmp directory=data_dir full=y logfile=expdp.log //2. schemas按用户导出 expdp user/passwd@orcl schemas=user dumpfile=expdp.dmp directory=data_dir logfile=expdp.log //3. 按表空间导出 expdp sys/passwd@orcl tablespace=tbs1,tbs2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log //4. 导出表 expdp user/passwd@orcl tables=table1,table2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log //5. 按查询条件导出 expdp user/passwd@orcl tables=table1='where number=1234' dumpfile=expdp.dmp directory=data_dir logfile=expdp.log2.4 导入
//1、“full=y”,全量导入数据库; impdp user/passwd directory=data_dir dumpfile=expdp.dmp full=y //2、同名用户导入,从用户A导入到用户A; impdp A/passwd schemas=A directory=data_dir dumpfile=expdp.dmp logfile=impdp.log; //3.1从A用户中把表table1和table2导入到B用户中; impdp B/passwdtables=A.table1,A.table2 remap_schema=A:B directory=data_dir dumpfile=expdp.dmp logfile=impdp.log; //3.2将表空间TBS01、TBS02、TBS03导入到表空间A_TBS,将用户B的数据导入到A,并生成新的oid防止冲突; impdp A/passwd remap_tablespace=TBS01:A_TBS,TBS02:A_TBS,TBS03:A_TBS remap_schema=B:A FULL=Y transform=oid:n directory=data_dir dumpfile=expdp.dmp logfile=impdp.log //4、导入表空间; impdp sys/passwd tablespaces=tbs1 directory=data_dir dumpfile=expdp.dmp logfile=impdp.log //5、追加数据; impdp sys/passwd directory=data_dir dumpfile=expdp.dmp schemas=system table_exists_action=replace logfile=impdp.log; --table_exists_action://导入对象已存在时执行的操作。有效关键字:SKIP,APPEND,REPLACE和TRUNCATE



