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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 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.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings Jun 05, 2024 pm 10:21 PM

To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.

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.

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Mar 12, 2025 pm 05:48 PM

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

See all articles