Home Database Mysql Tutorial IT忍者神龟之DatabaseLink详解

IT忍者神龟之DatabaseLink详解

Jun 07, 2016 pm 04:02 PM
create ninja Detailed explanation

创建 CREATE public database link test_link CONNECT TO scott IDENTIFIED BY tiger using (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = LEE) ) ); --使用 select enam

创建 CREATE public database link test_link CONNECT TO scott IDENTIFIED BY tiger using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = LEE) ) )'; --使用 select ename from emp@test_link; --删除 drop public database link TEST_LINK;

一:dblink创建:

1、已经配置本地服务
create public database
link toBeJing connect to scott
identified by tiger using 'BEJING'

数据库连接字符串'BEJING'是当前客户端数据库中TNSNAMES.ORA文件里定义的别名名称.可以用NET8 EASY CONFIG或者直接修改TNSNAMES.ORA里定义.

2、直接建立链接

create database link toBeJing
 connect to scott identified by tiger
 using '(DESCRIPTION =
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST = X.X.X.X )(PORT = 1521))
 )
 (CONNECT_DATA =
 (SERVICE_NAME = BJORCL)
 )
 )';

create database link toIAS
connect to ias identified by cis
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cis1.com)
)
)';
Copy after login

host=数据库的ip地址,service_name=数据库的ssid。

其实两种方法配置dblink是差不多的,我个人感觉还是第二种方法比较好,这样不受本地服务的影响。

注意: 假如创建全局dblink,则必须使用systm或sys用户,在database前加public。

1.先创建PUBLIC DATABASE LINK,不用指定用户和密码 

scott@TEST>conn system/test
 Connected.
system@TEST>CREATE PUBLIC DATABASE LINK orcl USING 'BEJING';
Database link created.
Copy after login


2.再在各个用户下创建私有DATABASE LINK(同PUBLIC DATABASE LINK名称相同),指定用户和密码

system@TEST>conn scott/tiger
 Connected.
 scott@TEST>CREATE DATABASE LINK orcl CONNECT TO scott IDENTIFIED BY tiger;
 Database link created.
Copy after login

实际上相当于: 

CREATE DATABASE LINK orcl USING 'BEJING' CONNECT TO scott IDENTIFIED BY tiger;

db link 有3种类型,我这里只讨论其中两种,connected user和fixed user。
connected user,简单来说,连接方数据库以connected的用户来连接远程数据库。
fixed user,简单来说,连接方数据库以fixed(指定的)用户来连接远程数据库。

看看创建db link语法,你对这两种类型就比较清楚了。

创建connected user的db link语法:

create databas link foo connect to scott identified by tiger using 'BEJING' ;
Copy after login

创建fixed user的db link语法:

create databas link foo using 'BEJING' ;
Copy after login

db link 的命名和global_names有关,global_name是数据库全局名称,global_name在你所管理的数据库中要保证唯一。数据库名称是db_name。数据库名称一般都取得比较短,我的习惯一般取长度4个字符,重名概率高。

所以,oracle模仿域名搞出一个global_name,global_name=db_name+db_domain。
有了global_name,就可以实现数据库命名的全局唯一。例:ORCL.REGRESS.RDBMS.DEV.US.ORACLE.COM

数据库全局名称可以用以下命令查出

SELECT * FROM GLOBAL_NAME;
Copy after login

如果global_names=true,那么db link的命名要和远程数据库的global_name相同;
如果global_names=false,那么你可以随便命名db link。

查询global_names是true还是false,在pl/sql中的命令窗口(不是sql窗口)执行:show parameter global_names

二、dblink查询:

查看所有的数据库链接,进入系统管理员SQL>操作符下,运行命令:

SQL>select owner,object_name from dba_objects where object_type='DATABASE LINK';
Copy after login

三、dblink删除:

DROP PUBLIC DATABASE LINK toBeJing
Copy after login

四、dblink使用:

SELECT……FROM表名@数据库链接名;
Copy after login

查询、删除和插入数据和操作本地的数据库是一样的,只不过表名需要写成“表名@dblink服务器”而已。

例:查询北京数据库中emp表数据 select * from emp@toBeJing;

五、同义词配合:

第四点中from emp@toBeJing可以创建同义词来替代:

CREATE SYNONYM同义词名FOR 表名;

CREATE SYNONYM同义词名FOR 表名@数据库链接名;

如:create synonym bj_scott_emp for emp@toBeJing;

于是就可以用bj_scott_emp来替代带@符号的分布式链接操作emp@toBeJing

DB LINK是独立于创建用户(USER_DB_LINKS的USERNAME)起作用的,其他用户无法使用这个连接,无权限也不能删除它。

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of obtaining administrator rights in Win11 Detailed explanation of obtaining administrator rights in Win11 Mar 08, 2024 pm 03:06 PM

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

How to create a folder on Realme Phone? How to create a folder on Realme Phone? Mar 23, 2024 pm 02:30 PM

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

How to create pixel art in GIMP How to create pixel art in GIMP Feb 19, 2024 pm 03:24 PM

This article will interest you if you are interested in using GIMP for pixel art creation on Windows. GIMP is a well-known graphics editing software that is not only free and open source, but also helps users create beautiful images and designs easily. In addition to being suitable for beginners and professional designers alike, GIMP can also be used to create pixel art, a form of digital art that utilizes pixels as the only building blocks for drawing and creating. How to Create Pixel Art in GIMP Here are the main steps to create pixel pictures using GIMP on a Windows PC: Download and install GIMP, then launch the application. Create a new image. Resize width and height. Select the pencil tool. Set the brush type to pixels. set up

Detailed explanation of division operation in Oracle SQL Detailed explanation of division operation in Oracle SQL Mar 10, 2024 am 09:51 AM

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

How to create a family with Gree+ How to create a family with Gree+ Mar 01, 2024 pm 12:40 PM

Many friends expressed that they want to know how to create a family in Gree+ software. Here is the operation method for you. Friends who want to know more, come and take a look with me. First, open the Gree+ software on your mobile phone and log in. Then, in the options bar at the bottom of the page, click the "My" option on the far right to enter the personal account page. 2. After coming to my page, there is a "Create Family" option under "Family". After finding it, click on it to enter. 3. Next jump to the page to create a family, enter the family name to be set in the input box according to the prompts, and click the "Save" button in the upper right corner after entering it. 4. Finally, a "save successfully" prompt will pop up at the bottom of the page, indicating that the family has been successfully created.

How to Create a Contact Poster for Your iPhone How to Create a Contact Poster for Your iPhone Mar 02, 2024 am 11:30 AM

In iOS17, Apple has added a contact poster feature to its commonly used Phone and Contacts apps. This feature allows users to set personalized posters for each contact, making the address book more visual and personal. Contact posters can help users identify and locate specific contacts more quickly, improving user experience. Through this feature, users can add specific pictures or logos to each contact according to their preferences and needs, making the address book interface more vivid. Apple in iOS17 provides iPhone users with a novel way to express themselves, and added a personalizable contact poster. The Contact Poster feature allows you to display unique, personalized content when calling other iPhone users. you

A first look at Django: Create your first Django project using the command line A first look at Django: Create your first Django project using the command line Feb 19, 2024 am 09:56 AM

Start the journey of Django project: start from the command line and create your first Django project. Django is a powerful and flexible web application framework. It is based on Python and provides many tools and functions needed to develop web applications. This article will lead you to create your first Django project starting from the command line. Before starting, make sure you have Python and Django installed. Step 1: Create the project directory First, open the command line window and create a new directory

Detailed explanation of the role and usage of PHP modulo operator Detailed explanation of the role and usage of PHP modulo operator Mar 19, 2024 pm 04:33 PM

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

See all articles