1.首先我建立了一个名为"dd”的用户并且将其密码设为“dd123” (以sys身份进行操作的sql语句)
create user dd identified by dd123;
2.为新 用户分配一些权限
grant create session to dd;
grant create table to dd;
3.新建一个目录用来存放文件。(root身份在服务器上进行的操作。并且为该目修改所有者及组属性)
[root@zzu ~]# cd /u01/
[root@zzu u01]# mkdir ts
[root@zzu u01]# chown -R oracle:oinstall ts
4.创建名为“dd” (表空间)tablespace。并且将dd用户加入到dd表空间。并且给他分配一定的空间使用配额(sys身份)
create tablespace dd
datafile '/u01/ts/dd001.dbf'
size 20m ;
alter user dd default tablespace dd;
alter user dd quota 20m on dd;
5.使用dd账户登录。创建一张名称为test1的测试表。
create table test1(
ts int,tsname varchar2(30));
6.建立备份目录并使用exp对数据进行导出(在服务器上执行)
[oracle@zzu u01]$ mkdir dump
[root@zzu u01]# chown -R oracle:oinstall dump
[root@zzu u01]# chmod 775 dump
[oracle@zzu dump]$ exp
Export: Release 10.2.0.1.0 - Production on Wed May 16 06:44:20 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Username: sys as sysdba
Password:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 >
Export file: expdat.dmp > /u01/dump/emp052209.dmp --为要备份的对象选择目标文件及存储路径
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > t --在这里悬着对表备份
Export table data (yes/no): yes >
Compress extents (yes/no): yes > --默认压缩备份文件
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > scott.emp --所要导出的表,指定该表的用户名
Current user changed to SCOTT
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >
Export terminated successfully with warnings.
此时已经完成备份
7.使用imp导入备份
[oracle@zzu dump]$ imp
Import: Release 10.2.0.1.0 - Production on Wed May 16 07:07:21 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Username: sys as sysdba
Password:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Import file: expdat.dmp > /u01/empo52209.dmp --指定要导入的备份文件及所在的路径
IMP-00002: failed to open /u01/empo52209.dmp for read
Import file: expdat.dmp > /u01/dump/emp052209.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V10.02.01 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >
Ignore create error due to object existence (yes/no): no > yes --忽略错误提示
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no >
Username: scott --该表的所属用户
Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done:
. importing SYS's objects into SYS
. importing SCOTT's objects into SCOTT
. . importing table "EMP" 14 rows imported
About to enable constraints...
Import terminated successfully with warnings.
[oracle@zzu dump]$
这个过程就是逻辑备份