search
HomeDatabaseMysql TutorialOracle数据库的导入导出

Oracle数据库的导入导出 作者:赵磊 博客:http://elf8848.iteye.com 一、背景介绍 9i,10g,11g 支持Export 与 Import工具,以后的版本将不在支持。建议改用数据泵,数据泵是Export 与 Import工具加强。 Export 与 Import的操作是针对*.dmp文件的,是oracle专

Oracle数据库的导入导出


作者:赵磊

博客:http://elf8848.iteye.com

 

一、背景介绍 

 

9i,10g,11g 支持Export 与 Import工具,以后的版本将不在支持。建议改用数据泵,数据泵是Export 与 Import工具加强。

 

Export 与 Import的操作是针对*.dmp文件的,是oracle专有的二进制格式。适合从oracle导入到oracle。

 

Export 与 Import对于大数据量(上G) 的导入导出已不适合。

 

SQL Loader这种导入工具是针对文本文件的。适合从文本文件导入到oracle。是执行insert语句的插入原理

 

Direct Load工具,直接加载,是从oracle块对oracle块的导数据,速度很多,适合从oracle导入到oracle。

 

 

二、使用Export 与 Import工具 对数据导入导出

 

工具在oracle  bin 目录下的 exp.exe , imp.exe 这两个工具

可在客户端或服务端运行

 

2.1、导出*.dmp文件

 

2.1.1 exp的四种模式:

1、表模式,用于导出某张表。

2、用户模式,用于导出某用户的Schema。

3、表空间模式,用于导出表空间。表空间的是由数据文件组成的,把数据文件从当前库copy到目标库,在用exp工具从当前库导出这个表空间的字典信息再导入到目标库,分两步走。限制较多。

4、数据库模式。用于导出整个数据库,不适合大数据量。

 

2.1.2  导出例子

 

导出1--用户模式

exp 用户名/密码@网络服务名 file=d:/oralce_bak_20101001.dmp owner=用户名 log=d:/exp.log direct=y

file:导出的*.dmp文件输出到指定目录

owner:导出哪个用户的Schema

log:日志文件输了到指定目录 (可选)

direct:y表示直接导出 (可选) 速度比一般导出快一倍以上,默认n

rows:y表示同时导出数据 (可选),默认值y,n表示只导表结构

 

导出2--表模式

exp 用户名/密码@网络服务名 file=20101001.dmp tables=表名1,表名2 rows=y  log=exp.log

file:导出的*.dmp文件输出到当前目录

tables:指定导出的表名,可以是多个,用逗号分隔

rows:y表示同时导出数据 (可选),默认值y,n表示只导表结构

log:日志文件输了到当前目录 (可选)

 

导出3--数据库模式

exp 用户名/密码@网络服务名 file=20101001.dmp full=y rows=y  log=exp.log grants=y

file:导出的*.dmp文件输出到当前目录

full:导出整个库

rows:y表示同时导出数据 (可选),默认值y ,n表示只导库结构

log:日志文件输了到当前目录 (可选)

grants: y表示导出授权 (可选)

 

2.1.3  导出时的字符集处理

 在源数据库与目标数据库字符集不同时,会发生字符集转换

 四个地方的字符集要先整清楚

 1、源数据库的字符集

 2、exp工具所在环境的字符集,你很可能在windows xp上运行exp导出远程oracle数据库的数据。

 3、imp工具所在环境的字符集,你很可能在windows xp上运行imp向远程的oracle数据库导入数据。

 4、目标数据库的字符集

 按最坏的情况计算,上面4个地方的字符集都不一样,最多会发生3次字符集的转换。转换时字符集不兼容就会发生乱码。

 

 查看数据库的字符集,数据库是英文linux系统:

 select * from nls_database_parameters;

 在查询结果中找三个地方:

     NLS_LANGUAGE -- American

     NLA_TERRITORY -- America

     NLS_CHARACTEREST -- AL32UTF8

     说明是:美国 AL32UTF8

 

 查看exp,imp工具所在环境的字符集,是windows xp系统:

 看注册表:HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/可能有多个oracle,一般是KEY_OraClient10g_home1  到这里,看右侧,找NLS_LANG项的值是:简体中文ZHS16GBK。

 说明是: 简体中文ZHS16GBK

 

 由于上面两处字符集不同,在导出导入时,共会发生两次字符集转换,如果想避免转换,做如下修改:

 

 修改exp,imp工具所在环境的字符集

 在windows xp命令行输入:SET NLS_LANG=American_America.AL32UTF8

 与数据库的字符集一致,是上面英文linux系统中数据库字符集的三个名称的组合。

 

  如果源数据库与目标数据库字符集不同,但exp工具与源数据库字符集一致, imp工具与目标数据库符集一致, 那么会在imp读*.dmp文件时发生字符集转换。

 如果源数据库与目标数据库字符集不同,但exp,imp工具与源数据库字符集一致, 那么会在目标数据库接收*.dmp时发生字符集转换。

 

 2.1.4 导出的权限

 用户默认可导出自己的表,想导出别人的表或Schema,要有exp_full_database权限

 grant exp_full_database to 用户名

 

 

 

 

2.2导入*.dmp文件

2.2.1 imp的四种模式:

与exp工具一样有四种模式,详见上面的exp的四种模式。

 

2.2.2  导入例子

 

导入1--用户模式

imp 用户名/密码@网络服务名 file=d:/oralce_bak_20101001.dmp ignore=y  fromuser=从哪个用户 touser=导入到哪个用户 tables=表名1,表名2

file:指明*.dmp文件位置

ignore:y:表已存在就不用再创建表了直接导入。 n表示创建表再导入。   默认为n,(可选)

fromuser:从哪个用户来 (可选)

touser:导入到哪个用户 (可选)

tables:指定导入的表名,可以是多个,用逗号分隔 (可选)

 

导入2--表模式

imp 用户名/密码@网络服务名 tables=表名1,表名2 rows=y file=2010.dmp

tables:指定导入的表名,可以是多个,用逗号分隔

rows:y表示同时导出数据 (可选),默认值y,n表示只导表结构

file:导入当前目录的*.dmp文件到数据库

 

imp 用户名/密码@网络服务名 file=d:/oralce_bak_20101001.dmp  show=y

show: y表示不导入,只看看。可以看看*.dmp是从哪个版本的库导出来的,好像也能看字符集。

 

使用DBA身份导入,空格部分要加单引号

imp \'用户名/密码@网络服务名 AS SYSDBA\'   tables=表名1,表名2 rows=y file=2010.dmp

 

 

 2.2.4 导入的权限

 用户默认可导入自己的表,想导入别人的表或Schema,要有exp_full_database权限

 grant exp_full_database to 用户名

 

 

 

 

 

三、使用数据泵 对数据导入导出

 

数据泵是Export 与 Import工具加强,工具在oracle  bin 目录下的 expdp.exe , impdp.exe 两个工具

只能在服务端运行

 

Statement
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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 Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)