- A+
第一步 查询创建表空间所需路径 file_name:以管理员system/admin 登录,查询数据文件名称、大小和路径的信息
- select tablespace_name,file_id,bytes,file_name from dba_data_files;
- select tablespace_name,file_id,bytes,file_name from dba_data_files;
第二步 创建表空间 :以管理员system/admin 登录,创建表空间
- CREATE TABLESPACE myTbSpace
- LOGGING
- DATAFILE 'D:/INSTALLSOFTWARE/MYORACLE/APP/ADMINISTRATOR/ORADATA/LWORCL/myTbSpace.DBF'
- SIZE 32 M
- AUTOEXTEND ON
- NEXT 32 M MAXSIZE 2048 M
- EXTENT MANAGEMENT LOCAL ;
CREATE TABLESPACE myTbSpace
LOGGING
DATAFILE 'D:/INSTALLSOFTWARE/MYORACLE/APP/ADMINISTRATOR/ORADATA/LWORCL/myTbSpace.DBF'
SIZE 32 M
AUTOEXTEND ON
NEXT 32 M MAXSIZE 2048 M
EXTENT MANAGEMENT LOCAL ;
第三步 创建用户 leiwei :以管理员system/admin 登录,创建用户,并授予用户雷伟创建dblink(所需权限见第四步)和view的权限
- -- Create the user
- create user LEIWEI
- identified by "leiwei"
- default tablespace myTableSpace
- temporary tablespace TEMP
- profile DEFAULT
- password expire ;
- -- Grant/Revoke role privileges
- grant connect to LEIWEI;
- grant resource to LEIWEI;
- -- Grant/Revoke system privileges
- grant create any view to LEIWEI;
- grant create database link to LEIWEI;
- grant create public database link to LEIWEI;
- grant drop public database link to LEIWEI;
- grant unlimited tablespace to LEIWEI;
-- Create the user
create user LEIWEI
identified by "leiwei"
default tablespace myTableSpace
temporary tablespace TEMP
profile DEFAULT
password expire ;
-- Grant/Revoke role privileges
grant connect to LEIWEI;
grant resource to LEIWEI;
-- Grant/Revoke system privileges
grant create any view to LEIWEI;
grant create database link to LEIWEI;
grant create public database link to LEIWEI;
grant drop public database link to LEIWEI;
grant unlimited tablespace to LEIWEI;
第四步 查看dblink需要哪些权限:以管理员system/admin 登录, 查看创建dblink需要哪些权限,将这些权限赋给对应用户如:leiwei
- select * from user_sys_privs t
- where t.privilege like upper( '%link%' );
select * from user_sys_privs t
where t.privilege like upper( '%link%' );
第五步 创建dblink :以普通用户leiwei/leiwei 登录,创建dblink
- -- Create database link
- create database link DBLINK2AREA
- connect to YPDOOR IDENTIFIED BY ypdoor
- using '(DESCRIPTION=(ADDRESS_LIST=
- (ADDRESS=(PROTOCOL=TCP)(HOST=172.23.1.30)(PORT=1521))
- )
- (CONNECT_DATA=
- (SERVICE_NAME=orcl)
- )
- )' ;
-- Create database link
create database link DBLINK2AREA
connect to YPDOOR IDENTIFIED BY ypdoor
using '(DESCRIPTION=(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.23.1.30)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=orcl)
)
)' ;
第六步 创建视图:以普通用户leiwei/leiwei 登录,创建view获取到dblink对象(172.23.1.30)数据库(orcl)中任意表(emp)的数据
- create or replace view dblinkview as
- select *
- from emp@DBLINK2AREA
create or replace view dblinkview as
select *
from emp@DBLINK2AREA
第七步 查询视图:以普通用户leiwei/leiwei 登录 ,查询视图 dblinkview验证数据是否link成功
- select * from dblinkview t
select * from dblinkview t
八、建立同义词
- -- Create the synonym
- create or replace synonym TELE_NOTE_GROUPS
- for PUSER.TELE_NOTE_GROUPS@DBLINK_PORTAL.REGRESS.RDBMS.DEV.US.ORACLE.COM;
-- Create the synonym
create or replace synonym TELE_NOTE_GROUPS
for PUSER.TELE_NOTE_GROUPS@DBLINK_PORTAL.REGRESS.RDBMS.DEV.US.ORACLE.COM;
九、导出库中对应用户下的数据
- exp ypdoor/ypdoor@172.18.27.146/lworcl file=d:/20111231ypdoor.dmp full=y
- exp ypdoor/ypdoor@172.18.27.146/lworcl file=d:/20111231ypdoor.dmp full=y