您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

oracle数据库的导入和导出

bubuko 2022/1/25 20:08:32 其他 字数 6257 阅读 852 来源 http://www.bubuko.com/infolist-5-1.html

oracle数据库的导入和导出 exp/imp 导入导出命令 它们是oracle自带的命令,所有版本通用的 exp 语法 userid:它是导出数据库的用户(一般使用system用户) file:指定导出的dump文件的路径(必须是oracle用户有权限的目录) log:指定导出时日志文件的存放路径 ...

oracle数据库的导入和导出

exp/imp

导入导出命令
它们是oracle自带的命令,所有版本通用的

exp

语法

exp userid=用户名/"密码"@IP|域名|主机名:端口号/数据库实例名 file='导出文件路径' log='日志文件路径' full=y|n tables=表名,... owner=模式(数据库用户) indexes=y|n
  • userid:它是导出数据库的用户(一般使用system用户)
  • file:指定导出的dump文件的路径(必须是oracle用户有权限的目录)
  • log:指定导出时日志文件的存放路径
  • full:表示全库导出(会将数据库的所有内容导出,包括数据字典等)
  • tables:指定要导出的数据库表
  • owner:指定导出的数据库模式(用户名)
  • indexes:Y|N 表示导出数据时,是否导出索引,默认是导出索引

按照用户导出

[oracle@localhost data]$ exp system/"oracle"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_scott.dump' log='/home/oracle/data/exp_scott.log' owner=scott indexes=n

这种方式,如果表中没有数据,是不会导出的

按照表导出

使用tables,而不使用owner了

[oracle@localhost data]$ exp scott/"scott"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_tables.dump' log='/home/oracle/data/exp_tables.log' tables=scott.dept,scott.emp indexes=n

全库导出

[oracle@localhost data]$ exp system/"oracle"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_full.dump' log='/home/oracle/data/exp_full.log' full=y indexes=n

imp导入命令

语法

imp userid=用户名/"密码"@ip:端口/实例名 file='导出文件路径' log='日志文件路径' fromuser=从哪个用户导入 touser=导入到哪个用户下 tables=表名 owner=模式 full=y|n

按用户导入

本地创建一个新用户,新用户使用新的表空间

SQL> create tablespace bow datafile '/u01/app/oracle/oradata/bow_data.dbf' size 1g autoextend onmited;

Tablespace created.
SQL> create temporary tablespace bowtemp tempfile '/u01/app/oracle/oradata/bow_temp.dbf' size 1g autoextend on next 100m maxsize unlimited;

Tablespace created.
SQL> create user bow default tablespace bow temporary tablespace bowtemp identified by bow;

User created.
SQL> grant connect,resource to bow;

Grant succeeded.
SQL> conn bow/bow
Connected.
SQL> select table_name from user_tables;

no rows selected
[oracle@localhost data]$ imp userid=system/"oracle"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_scott.dump' log='/home/oracle/data/imp_scott.log' fromuser=scott touser=bow;

再次查看bow用户下的表

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
DEPT
EMP
SALGRADE

按照表导入

SQL> conn scott/scott
Connected.

SQL> drop table emp;
Table dropped.

SQL> drop table dept;
Table dropped.
[oracle@localhost data]$ imp system/"oracle"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_tables.dump' log='/home/oracle/data/imp_tables.log' tables=dept,emp fromuser=scott touser=scott
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
BONUS
SALGRADE
DEPT
EMP

全库导入

imp system/"oracle"@192.168.0.33:1521/orcl file='/home/oracle/data/exp_full.dump' log='/home/oracle/data/imp_full.log' full=y

expdp/impdp

数据泵导出导入
oracle10g之后才有的命令
适用于导出导入大数据时使用
数据库泵的导出导入,需要使用到数据库的direcotry对象

语法

expdp userid=用户名/"密码"@IP:端口/实例名 directory=目录名称 dumpfile=dmp文件名 logfile=日志文件名 schemas=模式(用户名) tables=表名,... full=y|n

expdp

创建一个目录对象

[oracle@localhost data]$ mkdir /home/oracle/dmp
[oracle@localhost data]$ sqlplus / as sysdba

SQL> create directory DUMPPATH as '/home/oracle/dmp';
Directory created.

按照用户导出

空的表也会把表结构导出

[oracle@localhost data]$ expdp system/"oracle"@192.168.0.33:1521/orcl directory=DUMPPATH dumpfile=expdp_scott.dump logfile=expdp_scott.log schemas=scott

按照用户导出

[oracle@localhost data]$ expdp system/"oracle"@192.168.0.33:1521/orcl directory=DUMPPATH dumpfile=expdp_tables.dump logfile=expdp_tables.log tables=scott.emp,scott.dept

全库导出

[oracle@localhost data]$ expdp system/"oracle"@192.168.0.33:1521/orcl directory=DUMPPATH dumpfile=expdp_full.dump logfile=expdp_full.log full=y

impdp导入命令

语法

impdp userid=用户名/"密码"@ip:端口/实例名 directory=目录名 dumpfile=导出文件名 logfile=日志文件名 tables=表名,... repmap_schema=原模式:目标模式 full=y|n

按用户导入

将bow用户下的上次恢复的表删除

SQL> select table_name from user_tables;
no rows selected
[oracle@localhost dmp]$ impdp system/"oracle"@192.168.0.33:1521/orcl directory=DUMPPATH dumpfile=expdp_scott.dump logfile=impdp_scott.log remap_schema=scott:bow

查看

[oracle@localhost dmp]$ sqlplus bow/bow

SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
BONUS
SALGRADE
DEPT
EMP

按表导入

再次删除bow用户下的所有表

SQL> select table_name from user_tables;

no rows selected
[oracle@localhost dmp]$ impdp system/"oracle"@192.168.0.33:1521/orcl directory=DUMPPATH dumpfile=expdp_tables.dump logfile=impdp_tables.log remap_schema=scott:bow tables=scott.emp,scott.dept 

再次登录bow用户查看

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
DEPT
EMP

全库导入

impdp system/"oracle"@192.168.0.33/orcl directory=DUMPPATH dumpfile=expdp_full.dump logfile=impdp_full.log full=y

oracle数据库的导入和导出

原文:https://www.cnblogs.com/inmeditation/p/12402153.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶