mysqld 是传统的 MySQL 服务器进程。要与 NDB 集群一起使用,mysqld 需要构建时支持 NDB 存储引擎,这在从 https://dev.mysql.com/downloads/ 可获取的预编译二进制文件中已有。如果你从源码构建 MySQL,必须使用 CMake 并带上 -DWITH_NDB=1 或(已弃用的)-DWITH_NDBCLUSTER=1 选项来包含对 NDB 的支持。mysqld is the traditional MySQL server process.
To be used with NDB Cluster, mysqld needs to be
built with support for the NDB
storage engine, as it is in the precompiled binaries available
from https://dev.mysql.com/downloads/. If you build MySQL from
source, you must invoke CMake with the
-DWITH_NDB=1 or (deprecated)
-DWITH_NDBCLUSTER=1 option to
include support for NDB.
有关从源代码编译 NDB Cluster 的更多信息,请参见 第 25.3.1.4 节,“在 Linux 上从源代码构建 NDB Cluster”,以及 第 25.3.2.2 节,“在 Windows 上从源代码编译和安装 NDB Cluster”。For more information about compiling NDB Cluster from source, see Section 25.3.1.4, “Building NDB Cluster from Source on Linux”, and Section 25.3.2.2, “Compiling and Installing NDB Cluster from Source on Windows”.
(有关 mysqld 的选项和变量的信息,除了本节讨论的与 NDB Cluster 相关的内容外,请参见 第 25.4.3.9 节,“NDB Cluster 的 MySQL 服务器选项和变量”。)(For information about mysqld options and variables, in addition to those discussed in this section, which are relevant to NDB Cluster, see Section 25.4.3.9, “MySQL Server Options and Variables for NDB Cluster”.)
如果 mysqld 二进制文件已支持 Cluster,NDBCLUSTER 存储引擎默认仍然是禁用的。您可以使用以下两种方法中的任意一种来启用此引擎:If the mysqld binary has been built with
Cluster support, the NDBCLUSTER
storage engine is still disabled by default. You can use either of
two possible options to enable this engine:
在启动 mysqld 时,在命令行上使用
--ndbcluster作为启动选项。Use--ndbclusteras a startup option on the command line when starting mysqld.在您的
my.cnf文件的[mysqld]部分中插入包含ndbcluster的一行。Insert a line containingndbclusterin the[mysqld]section of yourmy.cnffile.
验证您的服务器是否启用了NDBCLUSTER存储引擎的一个简单方法是在 MySQL 监视器中 (mysql) 执行SHOW ENGINES语句。您应该在NDBCLUSTER行中看到Support列的值为YES。如果您看到此行的值为NO,或输出中没有显示此行,则说明您没有运行启用NDB的 MySQL 版本。如果您在此行看到DISABLED,则需要按照前面描述的两种方法之一启用它。An easy way to verify that your server is running with the
NDBCLUSTER storage engine enabled is
to issue the SHOW ENGINES statement
in the MySQL Monitor (mysql). You should see
the value YES as the Support
value in the row for NDBCLUSTER. If
you see NO in this row or if there is no such
row displayed in the output, you are not running an
NDB-enabled version of MySQL. If you
see DISABLED in this row, you need to enable it
in either one of the two ways just described.
要读取群集配置信息,MySQL 服务器至少需要三条信息:To read cluster configuration data, the MySQL server requires at a minimum three pieces of information:
MySQL 服务器自身的群集节点 IDThe MySQL server's own cluster node ID
管理服务器的主机名或 IP 地址The host name or IP address for the management server
可以连接到管理服务器的 TCP/IP 端口号The number of the TCP/IP port on which it can connect to the management server
节点 ID 可以动态分配,因此不必非要显式指定。Node IDs can be allocated dynamically, so it is not strictly necessary to specify them explicitly.
mysqld 参数 ndb-connectstring 用于在启动 mysqld 时在命令行上指定连接字符串,或者在 my.cnf 中指定。连接字符串包含管理服务器所在的主机名或 IP 地址,以及它使用的 TCP/IP 端口。The mysqld parameter
ndb-connectstring is used to specify the
connection string either on the command line when starting
mysqld or in my.cnf. The
connection string contains the host name or IP address where the
management server can be found, as well as the TCP/IP port it
uses.
在下面的示例中,ndb_mgmd.mysql.com 是管理服务器所在的主机,管理服务器在端口 1186 上监听集群消息:In the following example, ndb_mgmd.mysql.com is
the host where the management server resides, and the management
server listens for cluster messages on port 1186:
$> mysqld --ndbcluster --ndb-connectstring=ndb_mgmd.mysql.com:1186
请参阅 第 25.4.3.3 节,“NDB 集群连接字符串”,了解有关连接字符串的更多信息。See Section 25.4.3.3, “NDB Cluster Connection Strings”, for more information on connection strings.
根据这些信息,MySQL 服务器可以作为集群的完整参与者。(我们通常将以这种方式运行的 mysqld 进程称为 SQL 节点。)它完全了解所有集群数据节点及其状态,并与所有数据节点建立连接。在这种情况下,它能够将任何数据节点用作事务协调器,并读取和更新节点数据。Given this information, the MySQL server can act as a full participant in the cluster. (We often refer to a mysqld process running in this manner as an SQL node.) It is fully aware of all cluster data nodes as well as their status, and establishes connections to all data nodes. In this case, it is able to use any data node as a transaction coordinator and to read and update node data.
您可以在 mysql 客户端中使用 SHOW
PROCESSLIST 查看 MySQL 服务器是否已连接到集群。如果 MySQL 服务器已连接到集群,并且您拥有 PROCESS 权限,则输出的第一行如下所示:You can see in the mysql client whether a MySQL
server is connected to the cluster using SHOW
PROCESSLIST. If the MySQL server is connected to the
cluster, and you have the PROCESS
privilege, then the first row of the output is as shown here:
mysql> SHOW PROCESSLIST \G
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db:
Command: Daemon
Time: 1
State: Waiting for event from ndbcluster
Info: NULL
要参与 NDB 集群,mysqld 进程必须使用 两个选项 --ndbcluster 和 --ndb-connectstring(或其在 my.cnf 中的等效设置)启动。如果 mysqld 仅使用 --ndbcluster 选项启动,或者它无法联系到集群,就无法操作 NDB 表,也无法创建任何新表,无论存储引擎为何。后者限制是一种安全措施,旨在防止在 SQL 节点未连接到集群时创建与 NDB 表同名的表。如果您希望在 mysqld 进程未参与 NDB 集群时使用其他存储引擎创建表,您必须重新启动服务器,不使用 --ndbcluster 选项。To participate in an NDB Cluster, the mysqld
process must be started with both the
options --ndbcluster and
--ndb-connectstring (or their
equivalents in my.cnf). If
mysqld is started with only the
--ndbcluster option, or if it is
unable to contact the cluster, it is not possible to work with
NDB tables, nor is it
possible to create any new tables regardless of storage
engine. The latter restriction is a safety measure
intended to prevent the creation of tables having the same names
as NDB tables while the SQL node is
not connected to the cluster. If you wish to create tables using
a different storage engine while the mysqld
process is not participating in an NDB Cluster, you must restart
the server without the
--ndbcluster option.