Oracle数据库导入导出实用技巧分享

一、导出数据

导出数据是Oracle数据库常见的操作之一。下面我们将介绍如何使用expdp命令导出数据。

1、连接到Oracle数据库。

$ sqlplus username/password@database

2、使用expdp命令导出数据。

$ expdp username/password@database tablespaces=tablespace_name dumpfile=dump_file.dmp logfile=log_file.log

其中,tablespace_name是要导出的表空间名称,dump_file.dmp是导出数据的文件名,log_file.log是导出过程的日志文件名。

3、等待导出完成。

Export: Release 19.0.0.0.0 - Production on Tue Aug 17 10:04:36 2021
Version 19.9.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All rights 
reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYS"."SYS_EXPORT_TABLESPACE_01":  username/password@database tablespaces=tablespace_name dumpfile=dump_file.dmp logfile=log_file.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . exported "SCOTT"."EMP"                            4.039 KB       14 rows
. . exported "SCOTT"."DEPT"                           5.976 KB        4 rows
. . exported "SCOTT"."BONUS"                          0 KB            0 rows
. . exported "SCOTT"."SALGRADE"                       0 KB            0 rows
Master table "SYS"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
***************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLESPACE_01 is:
  /u01/app/oracle/admin/orcl/dpdump/dump_file.dmp
Job "SYS"."SYS_EXPORT_TABLESPACE_01" successfully completed at Tue Aug 17 10:08:18 2021 elapsed 0 00:03:42

4、查看导出的文件。

$ ls dump_file.dmp

二、导入数据

导入数据是Oracle数据库常见的操作之一。下面我们将介绍如何使用impdp命令导入数据。

1、连接到Oracle数据库。

$ sqlplus username/password@database

2、使用impdp命令导入数据。

$ impdp username/password@database tablespaces=tablespace_name dumpfile=dump_file.dmp logfile=log_file.log

其中,tablespace_name是要导入的表空间名称,dump_file.dmp是导入数据的文件名,log_file.log是导入过程的日志文件名。

3、等待导入完成。

Import: Release 19.0.0.0.0 - Production on Tue Aug 17 10:28:47 2021
Version 19.9.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All 
rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYS"."SYS_IMPORT_TABLESPACE_01":  username/password@database tablespaces=tablespace_name dumpfile=dump_file.dmp logfile=log_file.log
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. importing SCOTT's objects into SCOTT
. . importing table                          "EMP"         
. . importing partition                     "EMP": 
. . . 17 rows 
. . importing partition                     "EMP": 
. . . 19 rows 
. . importing partition                     "EMP": 
. . . 16 rows 
. . importing partition                     "EMP": 
. . . 24 rows 
. . importing partition                     "EMP": 
. . . 25 rows 
. . importing partition                     "EMP": 
. . . 27 rows 
. . importing partition                     "EMP": 
. . . 19 rows 
. . importing partition                     "EMP": 
. . . 18 rows 
. . importing partition                     "EMP": 
. . . 34 rows 
. . importing partition                     "EMP": 
. . . 26 rows 
. . importing partition                     "EMP": 
. . . 22 rows 
. . importing partition                     "EMP": 
. . . 20 rows 
. . importing table                          "DEPT"       
. . . 4 rows imported
. . importing table                          "BONUS"      
. . . 0 rows imported
. . importing table                          "SALGRADE"   
. . . 0 rows imported
Master table "SYS"."SYS_IMPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_IMPORT_TABLESPACE_01 is:
  /u01/app/oracle/admin/orcl/dpdump/dump_file.dmp
Job "SYS"."SYS_IMPORT_TABLESPACE_01" successfully completed at Tue Aug 17 10:41:19 2021 elapsed 0 00:12:31

4、查看导入的数据。

$ sqlplus username/password@database
SQL> select * from table_name;

三、导出表结构

导出表结构是有时我们需要备份数据库结构的一种操作。下面我们将介绍如何使用exp命令导出表结构。

1、连接到Oracle数据库。

$ sqlplus username/password@database

2、使用exp命令导出表结构。

$ exp username/password@database file=export_file.dmp log=log_file.log owner=owner_name

其中,export_file.dmp是导出表结构的文件名,log_file.log是导出过程的日志文件名,owner_name是要导出表的所有者。

3、等待导出完成。

Export: Release 19.0.0.0.0 - Production on Tue Aug 17 10:44:33 2021
Version 19.9.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All 
rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
Note: grants on tables/views/sequences/roles will not be exported
Note: indexes on tables will not be exported
Note: constraints on tables will not be exported
Note: triggers on tables will not be exported
Note: referential constraints will not be exported
Note: bitmap indexes on tables will not be exported
Note: materialized views will not be exported
Note: system defined tables will not be exported
Note: flashback query attributes are not exported
Note: data for table "SCOTT"."EMP" will not be exported
Note: data for table "SCOTT"."DEPT" will not be exported
Note: data for table "SCOTT"."BONUS" will not be exported
Note: data for table "SCOTT"."SALGRADE" will not be exported
Export terminated successfully without warnings.

4、查看导出的文件。

$ ls export_file.dmp

四、导入表结构

导入表结构是有时我们需要恢复数据库结构的一种操作。下面我们将介绍如何使用imp命令导入表结构。

1、连接到Oracle数据库。

$ sqlplus username/password@database

2、使用imp命令导入表结构。

$ imp username/password@database file=export_file.dmp log=log_file.log full=y

其中,export_file.dmp是导入表结构的文件名,log_file.log是导入过程的日志文件名,full=y表示导入所有对象。

3、等待导入完成。

Import: Release 19.0.0.0.0 - Production on Tue Aug 17 10:46:09 2021
Version 19.9.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All 
rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYS"."SYS_IMPORT_FULL_01":  username/password@database file=export_file.dmp log=log_file.log full=y
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."EMP"                            4.039 KB       14 rows
. . imported "SCOTT"."DEPT"                           5.976 KB        4 rows
. . imported "SCOTT"."BONUS"                          0 KB            0 rows
. . imported "SCOTT"."SALGRADE"                       0 KB            0 rows
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/SYS_PRIVILEGE
Processing object type SCHEMA_EXPORT/PRE_SYSTEM_PRIVILEGE
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE
Processing object type SCHEMA_EXPORT/PROFILE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/ROLE
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/PRIMARY/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/FOREIGN/INDEX
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/PRIMARY/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/GLOBAL_INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX_PARTITION
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/FOREIGN/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT/FK_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER/TRIGGER
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX_SUBPARTITION
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/PRIMARY/INDEX_PARTITION
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS_TYPE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS_TYPE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS_TYPE
Completed "SYS"."SYS_IMPORT_FULL_01"
********************************************************************************
Dump file set for SYS.SYS_IMPORT_FULL_01 is:
  /u01/app/oracle/admin/orcl/dpdump/export_file.dmp
Job "SYS"."SYS_IMPORT_FULL_01" successfully completed at Tue Aug 17 10:51:01 2021 elapsed 0 00:04:50

4、查看导入的表。

$ sqlplus username/password@database
SQL> select * from table_name;

五、自定义导出内容

有时候我们只需要导出特定的表或数据,而不是整个数据库。下面我们将介绍如何使用expdp命令自定义导出内容。

1、连接到Oracle数据库。

$ sqlplus username/password@database

2、使用expdp命令自定义导出内容。

$ expdp username/password@database tables=table_name directory=dir_name dumpfile=dump_file.dmp logfile=log_file.log

其中,table_name是要导出的表名,dir_name是导出文件的目录名,dump_file.dmp是导出数据的文件名,log_file.log是导出过程的日志文件名。

3、等待导出完成。

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/247264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝小蓝
上一篇 2024-12-12 13:20
下一篇 2024-12-12 13:20

相关推荐

  • Python 常用数据库有哪些?

    在Python编程中,数据库是不可或缺的一部分。随着互联网应用的不断扩大,处理海量数据已成为一种趋势。Python有许多成熟的数据库管理系统,接下来我们将从多个方面介绍Python…

    编程 2025-04-29
  • openeuler安装数据库方案

    本文将介绍在openeuler操作系统中安装数据库的方案,并提供代码示例。 一、安装MariaDB 下面介绍如何在openeuler中安装MariaDB。 1、更新软件源 sudo…

    编程 2025-04-29
  • 如何将Oracle索引变成另一个表?

    如果你需要将一个Oracle索引导入到另一个表中,可以按照以下步骤来完成这个过程。 一、创建目标表 首先,需要在数据库中创建一个新的表格,用来存放索引数据。可以通过以下代码创建一个…

    编程 2025-04-29
  • 数据库第三范式会有删除插入异常

    如果没有正确设计数据库,第三范式可能导致删除和插入异常。以下是详细解释: 一、什么是第三范式和范式理论? 范式理论是关系数据库中的一个规范化过程。第三范式是范式理论中的一种常见形式…

    编程 2025-04-29
  • leveldb和unqlite:两个高性能的数据库存储引擎

    本文将介绍两款高性能的数据库存储引擎:leveldb和unqlite,并从多个方面对它们进行详细的阐述。 一、leveldb:轻量级的键值存储引擎 1、leveldb概述: lev…

    编程 2025-04-28
  • Python怎么导入数据库

    Python是一种高级编程语言。它具有简单、易读的语法和广泛的库,让它成为一个灵活和强大的工具。Python的数据库连接类型可以多种多样,其中包括MySQL、Oracle、Post…

    编程 2025-04-28
  • Think-ORM数据模型及数据库核心操作

    本文主要介绍Think-ORM数据模型建立和数据库核心操作。 一、模型定义 Think-ORM是一个开源的ORM框架,用于简化在PHP应用中(特别是ThinkPHP)与关系数据库之…

    编程 2025-04-27
  • 如何使用Python将CSV文件导入到数据库

    CSV(Comma Separated Values)是一种可读性高、易于编辑与导入导出的文件格式,常用于存储表格数据。在数据处理过程中,我们有时需要将CSV文件导入到数据库中进行…

    编程 2025-04-27
  • Python批量导入数据库

    本文将介绍Python中如何批量导入数据库。首先,对于数据分析和挖掘领域,数据库中批量导入数据是一个必不可少的过程。这种高效的导入方式可以极大地提高数据挖掘、机器学习等任务的效率。…

    编程 2025-04-27
  • Activiti 6自动部署后不生成数据库act_hi_*的解决方法

    本文将从多个方面详细阐述Activiti 6自动部署后不生成数据库act_hi_*的问题,并提供对应的代码示例。 一、问题分析 在使用Activiti 6部署流程后,我们发现act…

    编程 2025-04-27

发表回复

登录后才能评论