本机:192.168.0.1
远程主机:192.168.0.2
(1)在本机上tnsnames.ora配置如下
ORCL_2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )
(2)在本机上创建数据库连接
CREATE DATABASE LINK link CONNECT TO backup IDENTIFIED BY backup USING 'ORCL_2';
注意: backup为192.168.0.2上的用户,密码为backup
###查看存在数据库连接
select owner,object_name from dba_objects where object_type='DATABASE LINK';
(3)测试
SELECT * FROM hada.hada@link;
####删除数据库连接
DROP DATABASE LINK link;
创建公共连接
CREATE PUBLIC DATABASE LINK link3 CONNECT TO backup IDENTIFIED BY backup USING 'ORCL_2' ;
public是全局dblink,即该数据库上所有用户都能查询,要sys或者system用户来创建(当然有sysdba权限的用户也可以的);如果不使用public就是私有dblink,只有创建该dblink的用户能查询查看连接是否成功.
SELECT * FROM backup.l@link3; SELECT * FROM hada.hada@link3; ###删除公共连接 DROP PUBLIC DATABASE LINK LINK3;