Import and export of oracle data based on EXPDP and IMPDP

Data import and export


Data Pump Export uses the tool EXPDP to export the metadata (object structure) or data of database objects into a dump file. The data pump import is to use the tool IMPDP to import the metadata and data in the dump file into the Oracle database. Assuming that the EMP table is accidentally deleted, you can use the IMPDP tool to import the structure information and data of the EMP.

Exporting or importing data using Data Pump mainly has the following advantages:

Data pump export and import can realize logical backup and logical recovery. By using EXPDP, database objects can be backed up into dump files; when tables are accidentally deleted or other misoperations can be used, objects and data in dump files can be imported into the database using IMPDP.
Data Pump export and import can move objects between database users. For example, use EXPDP to export and store objects in a SCOTT schema in a dump file, and then use IMPDP to import objects in a dump file into other database schemas.
Use Data Pump Import to move objects between databases.
The data pump can realize the transfer of table space, that is, transfer the table space of one database to another database.

Data pump tools EXPDP and IMPDP are faster than EXP and IMP.

EXPDP can export metadata (object structure) or data of database objects to storage files.

IMPDP can import the data stored in the file into the Oracle database.

Calling EXPDP and IMPDP only needs to be entered in the command prompt window, without successfully connecting to the database.

1. EXPDP export

EXPDP is a [server] tool, which can only be used on the Oracle server, not on the Oracle client.

The EXPDP provided by oracle can export [table] [schema] [table space] [full database] 4 kinds of data.

【Notice】

The EXPDP tool can only store the exported dump file in the disk directory corresponding to the dierctory object, but cannot directly specify the disk directory where the dump file is located.

Therefore, when ** using the EXPDP tool, first create a directory object, and you need to authorize the database to use the permission of the directory object **.

Premise: Create a directory object and grant a user permission to use the directory (I use the me user)

creat directory dump_dir as 'd:\dump';
grant read,write on directory dump_dir to me;

export table

Exporting a table refers to storing the structure of one or more tables and their data in a dump file.

Ordinary users can only export tables in their own schemas. If they want to export tables in other schemas, the user must have the EXP_FULL_DATABASE role or the DBA role.

When exporting tables, only tables in one schema can be exported at a time.

Example: Export dept and emp tables in me mode

--将文件转存储到tab.dmp文件中,文件位于dump_dir目录对象所对应的磁盘目录中。
C:\>expdp me/me123 driectory=dump_dir dumpfile=tab.dmp tables=emp,dept;

export mode

To export a schema is to store all object structures and data in one or more schemas into a dump file.

When exporting the schema, the user must have the DBA role or the EXP_FULL_DATABASE role.

Example: Export all objects in the me schema

C:\>expdp system/Sa123456 directory=dump_dir dumpfile=schema.dmp schemas=me;

export tablespace

Store all objects and data in one or more tablespaces into a dump file.

C:\>expdp systerm/Sa123456 directory=dump_dir dumpfile=tablespace.dmp tablespaces=users;

export full database

Store all objects and data in the database into a dump file.

It is required that the user must have the DBA role or the EXP_FULL_DATABASE role.

But objects in schemas such as SYS, ORDSYS, ORDPLUGINS, CTXSYS, MDSYS, LBACSYS, XDB, etc. will not be exported.

C:\>expdp system/Sa123456 directory=dump_dir dumpfile=fulldatabase.dmp full=y;

2. IMPDP import data

When data pump imports data, its dump file is stored in the disk directory corresponding to the directory object, and the disk directory where the dump file is located cannot be directly specified.

import table

Loads the structure and data of one or more tables placed in the dump file into the database.

You need to use the TABLES parameter when importing the schema.

Ordinary users can only be imported into their own schemas. If you want to import tables as other users, you must have the EXP_FULL_DATABASE role or the DBA role.

To import a table, you can import the table into the source schema, or you can import the table into other schemas.

Example: import dept, emp into system mode

C:\>impdp system/Sa123456 directory=dump_dir dumpfile=tab.dmp tables=me.dept,me.emp remap_schema=me:system;

import schema

Loads all objects in one or more schemas placed in the dump file into the database.

The SCHEMAS parameter is required when importing schemas.

Ordinary users can import objects into their own schemas. If they import schemas as users in other areas, the user must have the IMP_FULL_DATABASE role or the DBA role.

When importing a schema, you can import all of the schema's objects into the source schema, or you can import all of the schema's objects into another schema.

Example: Import all objects in me mode into system mode

C:\>impdp system/Sa123456 directory=dump_dir dumpfile=schema.dmp schemas=me remap_schema=me:system;

import tablespace

Loads all objects from one or more tablespaces placed in the dump file into the database.

You need to use the TABLESPACES parameter when importing tablespaces.

C:\>impdp system/Sa123456 directory=dump_dir dumpfile=tablespace.dmp tablespaces=tbsp_1;

import full database

Loads all objects and their associated data for all database objects placed in the dump file into the database.

The FULL parameter needs to be used when importing the full database.

C:\>impdp system/Sa123456 directory=dump_dir dumpfile=fulldatabase.dmp full=y;

Guess you like

Origin blog.csdn.net/m0_65559701/article/details/127857436
Recommended