Home Database Mysql Tutorial 使用expdp(非本地)远程导出数据

使用expdp(非本地)远程导出数据

Jun 07, 2016 pm 04:00 PM
o database

前段时间,需要从异地一个测试数据库中将测试数据(一张表)导入本地库,表数据量大约500万,字段160多个,开始用了exp/imp方式,速

背景:

前段时间,需要从异地一个测试数据库中将测试数据(一张表)导入本地库,表数据量大约500万,字段160多个,开始用了exp/imp方式,速度奇慢,不能忍,于是转而使用expdp/impdp方式。

expdp/impd介绍:

从10g开始,除了传统的exp/imp导入导出工具外,Oracle提供了expdp/impdp的数据泵导入导出工具。

从上看,Oracle数据泵由三部分组成:

>The command-line clients, expdp and impdp

>The DBMS_DATAPUMP PL/SQL package (also known as the Data Pump API)
 

>The DBMS_METADATA PL/SQL package (also known as the Metadata API)
 

The Data Pump clients, expdp and impdp, invoke the Data Pump Export utility and Data Pump Import utility, respectively.
数据泵客户端(expdp/impdp),分别会调用数据泵Data Pump Export/Import Utility应用工具。


The expdp and impdp clients use the procedures provided in the DBMS_DATAPUMP PL/SQL package to execute export and import commands, using the parameters entered at the command line. These parameters enable the exporting and importing of data and metadata for a complete database or for subsets of a database.
expdp/impdp客户端使用由DBMS_DATAPUMP PL/SQL包提供的存储过程来执行export/import命令,并且可以在命令行中添加参数,这些参数可以导入导出数据库中的数据和元数据或其中的一部分。

When metadata is moved, Data Pump uses functionality provided by the DBMS_METADATA PL/SQL package. The DBMS_METADATA package provides a centralized facility for the extraction, manipulation, and re-creation of dictionary metadata.

如果需要导入导出元数据,数据泵会使用DBMS_METADATA PL/SQL包提供的函数。DBMS_METADATA包会提供便捷的方法,用于抽取、控制和重建数据字典元数据。

The DBMS_DATAPUMP and DBMS_METADATA PL/SQL packages can be used independently of the Data Pump clients.
 

DBMS_DATAPUMP和DBMS_METADATA的PL/SQL包可以独立于数据泵客户端使用。

All Data Pump Export and Import processing, including the reading and writing of dump files, is done on the system (server) selected by the specified database connect string. This means that for unprivileged users, the database administrator (DBA) must create directory objects for the Data Pump files that are read and written on that server file system. (For security reasons, DBAs must ensure that only approved users are allowed access to directory objects.) For privileged users, a default directory object is available. See "Default Locations for Dump, Log, and SQL Files" for more information about directory objects.
 

所有的数据泵导入导出过程,包括读取和写入的dump文件,都在数据库服务器(server)上。这意味着对于非授权用户,DBA必须为数据泵文件创建服务器端可读写的目录对象,处于安全考虑,DBA必须确保只有授权用户可以访问这些目录对象。对于授权用户,可以使用默认的目录对象。

总结:

数据泵工具expdp/impdp工具,执行时其实是调用的两个PL/SQL包(一个对应数据,一个对应元数据),读取和写入的dump文件存储于服务器上directory目录对应的文件夹中。

问题来了,如果没有服务器的账号,即使可以导出,但如何获取到导出的dump呢?

现在的需求是,从本地服务器使用expdp从远程服务器导出一张表的数据,然后使用impdp导入到本地库,且没有远程服务器的登录账号。

一个远程数据表的导入导出问题,当然这里使用exp/imp完全可以做到,现在看看expdp/impdp如何做。

解决方案:通过dblink实现远程数据的导入导出。

1. 本地库创建dblink指向远程库。

create database link gf_local connect to username identified by password using 'tnsname';

2. 本地库创建directory目录对象。

create directory expdp_dir as '/home/oracle11g/expdp_dir/';

3. 本地库创建数据泵导出参数文件。

vi exp.par:

userid=username/password  //本地库的用户名密码,可用上面创建的dblink和directory目录。

directory=expdp_dir  //本地库创建的directory目录。

dumpfile=gf_expdp.dump  //dump文件名。

logfile=gf_expdp.log  //日志文件名。

tables=depkf15.t_cp  //要导出的表。

query='"where rownum

network_link=gf_local  //dblink名。

注意,这里有个小问题值得注意,tables=depkf15.t_cp,如果待导出表和登录用户不同,则这里需要添加导出的对象schema(用户),否则会报错。

4. 执行导出命令。

expdp parfile=exp.par

开始报错了,提示:

ORA-31631:需要权限

ORA-39149:无法将授权用户链接到非授权用户

此时需要授予远程数据库用户exp_full_database权限:

GRANT exp_full_database TO username;

接下来就是等待了,dump文件会存储至本地的expdp_dir指向路径下。

总结:

1. expdp/impdp是10g以上提供的数据泵工具,运行时会调用两个PL/SQL包,,当然也可以直接运行这两个PL/SQL包,没试过,如果大家试过,也可以分享出来。

使用expdp(非本地)远程导出数据

2. 导入数据库账户需要有imp_full_database权限,导出数据库账户需要有exp_full_database权限。

使用expdp(非本地)远程导出数据

3. expdp比exp更优,还有一些地方,比如从help=y可以看到expdp有更多的参数可选,其中expdp有COMPRESSION压缩参数可选,解释如下:

Reduce the size of a dump file.

Valid keyword values are: ALL, DATA_ONLY, [METADATA_ONLY] and NONE.

可参考secooler的这篇文章(),比对了四种参数的压缩比。

4. 由于我的实验中,远程库和本地库之间网络不是很好,因此实际效果上,exp和expdp都比较慢,也是因为用了dblink的方式,就没再深入了,这里只是为了说明expdp/impdp如何实现远程数据库的导出。

后经同事测试,一个800MB的文件,使用exp导出大约用了1小时,expdp只需要不到10分钟,请注意,这里未使用COMPRESSION参数。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

See all articles