在Oracle下如何创建database link 实践
物理上存放于网络的多个Oracle数据库,逻辑上可以看成一个单一的大型数据库,用户可以通过网络对异地数据库中的数据进行存取,而
物理上存放于网络的多个Oracle数据库,逻辑上可以看成一个单一的大型数据库,用户可以通过网络对异地数据库中的数据进行存取,而服务器之间的协同处理
对于工作站用户及应用程序而言是完全透明的,开发人员无需关心网络的链接细节、数据在网络节点中的具体分布情况和服务器间的协调工作过程。数据库之间的链
接建立在DATABASE LINK上。要创建一个DATABASE LINK,必须首先在建立链接的数据库上设置链接字符串,即配置一个远程数据库的本地网络服务名。
数据库全局名称可以用以下命令查出:
SQL>SELECT * FROM GLOBAL_NAME;
修改可以用以下语句来修改参数值:
SQL>ALTER SYSTEM SET GLOBAL_NAME=TRUE/FALSE;
oracle数据库之间进行连接通讯:
创建数据库链接的语法如下:
CREATE [PUBLIC] DATABASE LINK link_name
CONNECT TO username IDENTIFIED BY password
USING 'zytydic'
其中:
zytydic为本地tnsname.ora中定义的链接串,内容如下:
zytydic =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
)
(CONNECT_DATA =
(SID = orcl)
)
)
注意:创建数据库链接的帐号必须有CREATE DATABASE LINK或CREATE PUBLIC DATABASE LINK的系统权限,用来登录到远程数据库的帐号必须有CREATE SESSION权限。
这两种权限都包含在CONNECT角色中(CREATE PUBLIC DATABASE LINK权限在DBA中)。一个公用数据库链接对于数据库中的所有用户都是可用的,,而一个私有链接仅
对创建它的用户可用。由一个用户给另外一个用户授权私有数据库链接是不可能的,一个数据库链接要么是公用的,要么是私有的。
创建数据库链接时,还可以使用缺省登录方式,即不指定远程数据库的用户名和密码:
create public database link test_default_type_dblink
using 'zytydic';
在不指定用户名和口令的情况下,ORACLE使用当前的用户名和口令登录到远程数据库,假如你本地是以emcd用户登录的本地的数据库db_A,那么创建的DB
Link test_default_type_dblink就是以本地的用户账户信息建立的,当要以此DB Link连接查看远程的数据库db_B的数据信息时,前提必须是db_B上也有
同样的账户存在,即db_B上也有账户emcd且密码和db_A上的emcd的密码也是一致的,否则此DB Link不可用。USING后面指定的是链接字符串,也就是远程
数据库的网络服务名,这个服务名保存在TNSNAMES.ORA文件中,在该文件中定义了协议、主机名、端口和数据库名。
如果有两台数据库服务器db_A和db_B,db_A下用户user_a需要用database link访问到db_B下user_b的数据时,有如下步骤:
(a).首先用户user_b,这个用户必须要有select 权限.
(b).在db_A上的tnsnames.ora中需要建立一个连接字符串,即上面的zytydic,可以从db_A连接到db_B.
(c).然后在登陆到db_A上建立db link,格式如下:
create database link link_A_to_B_name connect to user_b identified by user_b的password using 'tnsname_AtoB';
tnsname_AtoB就是到tnsname.ora中远程主机的连接字符串
在我自己的机子上建立的实际的DB Link SQL语句如下:
create database link taowei_to_101 connect to ga_bzk identified by ga_bzk using 'zytydic';
(d).测试是否能够读取数据.
select * from dual@link_AtoB_name结果为:DUMMY X表示设置成功
这时候就可以通过taowei_to_101查看远程主机上相关的数据信息了:
select * from tbl_bjflb@taowei_to_101;
删除数据库链接的语句是:
DROP [PUBLIC] DATABASE LINK taowei_to_101
数据库链接的引用
一般情况下引用数据库链接,可以直接将其放到调用的表名或视图名称后面,中间使用一个 @ 作为分割符:
SELECT * FROM tbl_bjflb@taowei_to_101;
对于经常使用的数据库链接,可以建立一个本地的同义词,方便使用:
CREATE SYNONYM tbl_bjflb__syn FOR tbl_bjflb@taowei_to_101;
还可以建立一个本地的远程视图,方便使用:
CREATE VIEW tbl_bjflb AS SELECT * FROM tbl_bjflb@taowei_to_101 where… ;
现在本视图可与本地数据库中的任何其它视图一样对待,也可以授权给其它用户,访问此视图,但该用户必须有访问数据库链接的权限。
对于另外一种情况,所要访问的表不在数据库链接中指定的远程帐户下,但该帐户有访问该表的权限,那么我们在表名前要加上该表的用户名:
SELECT * FROM emcd.emcd_data_source@taowei_to_101 ;
还可以建立快照(snapshot)通过dblink实现远程数据自动传输。
查看所有的数据库链接,进入系统管理员SQL>操作符下,运行命令:
SQL>select owner,object_name from dba_objects where object_type='DATABASE LINK';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.
