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/zh-tw/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

發表回復

登錄後才能評論