8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

18.8.2 如何创建 FEDERATED 表18.8.2 How to Create FEDERATED Tables

要创建一个 FEDERATED 表,应按照以下步骤进行:To create a FEDERATED table you should follow these steps:

  1. 在远程服务器上创建表。或者,记录现有表的表定义,可以使用 SHOW CREATE TABLE 语句来获取。Create the table on the remote server. Alternatively, make a note of the table definition of an existing table, perhaps using the SHOW CREATE TABLE statement.

  2. 在本地服务器上创建具有相同表定义的表,但添加将本地表连接到远程表的连接信息。Create the table on the local server with an identical table definition, but adding the connection information that links the local table to the remote table.

例如,您可以在远程服务器上创建以下表:For example, you could create the following table on the remote server:

CREATE TABLE test_table (
    id     INT(20) NOT NULL AUTO_INCREMENT,
    name   VARCHAR(32) NOT NULL DEFAULT '',
    other  INT(20) NOT NULL DEFAULT '0',
    PRIMARY KEY  (id),
    INDEX name (name),
    INDEX other_key (other)
)
ENGINE=MyISAM
DEFAULT CHARSET=utf8mb4;

要创建与远程表联邦的本地表,有两种可用选项。您可以创建本地表并指定用于连接远程表的连接字符串(包含服务器名称、登录名、密码),使用 CONNECTION,或者您可以使用之前使用 CREATE SERVER 语句创建的现有连接。To create the local table that is federated to the remote table, there are two options available. You can either create the local table and specify the connection string (containing the server name, login, password) to be used to connect to the remote table using the CONNECTION, or you can use an existing connection that you have previously created using the CREATE SERVER statement.

Important

当您创建本地表时,它 必须 与远程表具有相同的字段定义。When you create the local table it must have an identical field definition to the remote table.

Note

通过在主机上的表中添加索引,可以提高 FEDERATED 表的性能。优化的原因是发送到远程服务器的查询包含 WHERE 子句的内容,并发送到远程服务器,然后在本地执行。这减少了否则需要从服务器请求整个表以进行本地处理的网络流量。You can improve the performance of a FEDERATED table by adding indexes to the table on the host. The optimization occurs because the query sent to the remote server includes the contents of the WHERE clause and is sent to the remote server and subsequently executed locally. This reduces the network traffic that would otherwise request the entire table from the server for local processing.