文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

15.1.18 CREATE SERVER 语句15.1.18 CREATE SERVER Statement

CREATE SERVER server_name
    FOREIGN DATA WRAPPER wrapper_name
    OPTIONS (option [, option] ...)

option: {
    HOST character-literal
  | DATABASE character-literal
  | USER character-literal
  | PASSWORD character-literal
  | SOCKET character-literal
  | OWNER character-literal
  | PORT numeric-literal
}

此语句用于创建一个服务器定义,以便用于 FEDERATED 存储引擎。CREATE SERVER 语句会在 mysql 数据库的 servers 表中创建一行新记录。此语句需要 SUPER 权限。This statement creates the definition of a server for use with the FEDERATED storage engine. The CREATE SERVER statement creates a new row in the servers table in the mysql database. This statement requires the SUPER privilege.

server_name 应该是服务器的唯一引用。服务器定义在服务器范围内是全局的,无法限定服务器定义到特定数据库。server_name 的最大长度为 64 个字符(超过 64 个字符的名称会被静默截断),且不区分大小写。你可以将名称指定为带引号的字符串。The server_name should be a unique reference to the server. Server definitions are global within the scope of the server, it is not possible to qualify the server definition to a specific database. server_name has a maximum length of 64 characters (names longer than 64 characters are silently truncated), and is case-insensitive. You may specify the name as a quoted string.

wrapper_name 是一个标识符,可以用单引号引起来。The wrapper_name is an identifier and may be quoted with single quotation marks.

对于每个 option,必须指定字符字面量或数字字面量。字符字面量为 UTF-8 编码,支持最大 64 个字符,默认为空字符串。字符串字面量会被静默截断为 64 个字符。数字字面量必须是 0 到 9999 之间的数字,默认值为 0。For each option you must specify either a character literal or numeric literal. Character literals are UTF-8, support a maximum length of 64 characters and default to a blank (empty) string. String literals are silently truncated to 64 characters. Numeric literals must be a number between 0 and 9999, default value is 0.

Note

OWNER 选项目前不适用,对已创建的服务器连接的拥有权或操作没有影响。The OWNER option is currently not applied, and has no effect on the ownership or operation of the server connection that is created.

CREATE SERVER 语句在 mysql.servers 表中创建一条条目,稍后可以在创建 FEDERATED 表时与 CREATE TABLE 语句一起使用。你指定的选项用于填充 mysql.servers 表中的列。表的列包括 Server_name、Host、Db、Username、Password、Port 和 Socket。The CREATE SERVER statement creates an entry in the mysql.servers table that can later be used with the CREATE TABLE statement when creating a FEDERATED table. The options that you specify are used to populate the columns in the mysql.servers table. The table columns are Server_name, Host, Db, Username, Password, Port and Socket.

例如:For example:

CREATE SERVER s
FOREIGN DATA WRAPPER mysql
OPTIONS (USER 'Remote', HOST '198.51.100.106', DATABASE 'test');

请务必指定建立与服务器连接所需的所有选项。用户名、主机名和数据库名是必需的。其他选项也可能需要,例如密码。Be sure to specify all options necessary to establish a connection to the server. The user name, host name, and database name are mandatory. Other options might be required as well, such as password.

存储在表中的数据可以在创建FEDERATED表连接时使用:The data stored in the table can be used when creating a connection to a FEDERATED table:

CREATE TABLE t (s1 INT) ENGINE=FEDERATED CONNECTION='s';

有关更多信息,请参见第 18.8 节,“FEDERATED 存储引擎”。For more information, see Section 18.8, “The FEDERATED Storage Engine”.

CREATE SERVER会导致隐式提交。请参见第 15.3.3 节,“导致隐式提交的语句”。CREATE SERVER causes an implicit commit. See Section 15.3.3, “Statements That Cause an Implicit Commit”.

无论使用何种日志记录格式,CREATE SERVER都不会写入二进制日志。CREATE SERVER is not written to the binary log, regardless of the logging format that is in use.