13.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
}

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

The server_name should be a unique reference to the server. server_name应该是对服务器的唯一引用。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. server_name的最大长度为64个字符(超过64个字符的名称将被自动截断),并且不区分大小写。You may specify the name as a quoted string.您可以将名称指定为带引号的字符串。

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

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

Note注意

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

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. CREATE SERVER语句在mysql.servers表中创建一个条目,稍后在创建FEDERATED时可以与CREATE TABLE语句一起使用。The options that you specify are used to populate the columns in the mysql.servers table. 您指定的选项用于填充mysql.servers表中的列。The table columns are Server_name, Host, Db, Username, Password, Port and Socket.表列为Server_nameHostDbUseramePasswordPortSocket

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.还可能需要其他选项,例如密码。

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

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

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

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

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