Export:> Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition> With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
[oracle@aliyun_test oracle]$ ll /oracle/test/scott_emp.dmp
-rw-r--r-- 1 oracle oinstall 16384 Sep 26 14:38 /oracle/test/scott_emp.dmp
导出多张表
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g tables=emp,dept file=/oracle/test/scott_emp_dept.dmp
Export:> Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition> With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
. . exporting table DEPT 4 rows exported
EXP-00091: Exporting questionable statistics. 这里出现警告信息,查出是字符集的问题
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
字符集不匹配导致的,首先查询数据库的字符集
SQL> select sys_context('userenv','language') from dual;
SYS_CONTEXT('USERENV','LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
然后再在设置与之相同的字符集
[oracle@aliyun_test oracle]$ export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
然后再导出多张表的数据
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g tables=emp,dept file=/oracle/test/scott_emp_dept.dmp
Export:> Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition> With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
. . exporting table DEPT 4 rows exported
Export terminated successfully without warnings.
发现警告消失了,成功解决警告信息
上述执行的是Scott用户导出自己的表,下面介绍用system用户来导出scott用户的表
[oracle@aliyun_test oracle]$ exp userid=system/redhat@orcl11g tables=scott.emp file=/oracle/test/system_emp.dmp
Export:> Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition> With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
About to export specified tables via Conventional Path ...
Current user changed to SCOTT
. . exporting table EMP 14 rows exported
Export terminated successfully without warnings.
只需要修改相应的表信息就行
导出表的结构,只导出结构
3、导出表的结构
exp userid=scott/redhat@orcl11g tables=emp file=/oracle/test/emp_table.dmp rows=n
4、使用直接导出方式
exp userid=scott/redhat@ocrl11g tables=emp file=/oracle/test/emp_direct.dmp direct=y
这种方式比默认的常规方式速度要快,当数据量大时,可以考虑使用此种方法
这种方法需要数据库的字符集和客户端的字符集完全一致,否则会报错
导出方案
导出方案是指使用export工具导出一个方案或是多个方案中的所有对象(表、视图、索引等等)和数据,并将它存放到文件中
1、导出自己的方案
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g owner=scott file=/oracle/test/schema_scott.dmp
Export:> Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition> With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SCOTT
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SCOTT
About to export SCOTT's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SCOTT's tables via Conventional Path ...
. . exporting table DEPT 4 rows exported
. . exporting table EMP 14 rows exported
. . exporting table SALGRADE 5 rows exported
. . exporting table STUDENT 0 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
2、导出其他的方案
如果用户要导出其他方案,则需要dba的权限或是exp_full_database的权限,例如用system用户
就可以导出任何方案
exp userid=system/redhat@orcl11g owner=system,scott file=/oracle/test/system_scott.dmp
示例表示使用system用户不能导出sys的schema
导出整个数据库
导出数据库是指利用export导出所有数据库中的对象及数据,要求该用户具有dba的权限
或者是exp_full_database权限
exp userid=system/redhat@orcl11g full=y inctype=comlete file=/oracle/test/full_oracle.dmp
导入表
1、导入表
imp userid=scott/redhat@orcl11g tables=emp file=
模拟删除一张表,然后进行导出数据?
[oracle@oracle11g ~]$ exp userid=scott/redhat@orcl11g tables=student
file=/oracle/test/student.dmp
SQL> drop table student;
Table dropped
SQL> desc student;
Object student does not exist
然后imp进行导入数据
$ imp userid=scott/redhat@orcl11g tables=student file=/oracle/test/student.dmp
最后查看表是否成功导入?
SQL> desc student;
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
XH NUMBER(4) Y
XM VARCHAR2(20) Y
SEX CHAR(2) Y
SAL NUMBER(7,2) Y
BIRTHDAY DATE Y
成功导入表数据
2、用system执行导入数据
模拟删除
SQL> drop table student;
Table dropped
然后导入表数据
$ imp userid=system/redhat@orcl11g tables=student file=/oracle/test/student.dmp touser=scott
然后查看
SQL> desc student;
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
XH NUMBER(4) Y
XM VARCHAR2(20) Y
SEX CHAR(2) Y
SAL NUMBER(7,2) Y
BIRTHDAY DATE Y
3、导入表的结构
只导入表的结构而不导入数据
imp userid=scott/redhat@orcl11g tables=emp file= rows=n
4、导入数据
如果表的对象已经存在,那么就可以只导入数据,无需导入对象
imp userid=scott/redhat@orcl11g tables=emp file= ignore=y
导入方案
导入方案是指使用import工具将文件中的对象和数据导入到一个或多个方案中
如果要导入其他用户的方案,要求用户具有dba的权限,或者是imp_full_database的权限
1、导入自身的方案
imp userid=scott/redhat@orcl11g file=/oracle/test/schema_scott.dmp
2、导入其他用户的方案(利用system用户进行操作)
imp userid=system/redhat@orcl11g file=/oracle/test/schema_system_scott.dmp fromuser=system touser=scott
导入数据库
在默认情况下,当导入数据库时,会导入所有结构和数据
imp userid=system/redhat full=y file=/oracle/test/database.dmp