Cari di MySQL 
    MySQL Manual
Daftar Isi
(Sebelumnya) 16. Replication17.3. MySQL Cluster Configuration (Berikutnya)

Chapter 17. MySQL Cluster NDB 7.2

Daftar Isi

17.1. MySQL Cluster Overview
17.1.1. MySQL Cluster Core Concepts
17.1.2. MySQL Cluster Nodes, Node Groups, Replicas, and Partitions
17.1.3. MySQL Cluster Hardware, Software, and Networking Requirements
17.1.4. MySQL Cluster Development History
17.1.5. MySQL Server using InnoDB Compared with MySQL Cluster
17.1.6. Known Limitations of MySQL Cluster
17.2. MySQL Cluster Installation
17.2.1. Installing MySQL Cluster on Linux
17.2.2. Installing MySQL Cluster on Windows
17.2.3. Initial Configuration of MySQL Cluster
17.2.4. Initial Startup of MySQL Cluster
17.2.5. MySQL Cluster Example with Tables and Data
17.2.6. Safe Shutdown and Restart of MySQL Cluster
17.2.7. Upgrading and Downgrading MySQL Cluster NDB 7.2
17.3. MySQL Cluster Configuration
17.3.1. Quick Test Setup of MySQL Cluster
17.3.2. MySQL Cluster Configuration Files
17.3.3. Overview of MySQL Cluster Configuration Parameters
17.3.4. MySQL Server Options and Variables for MySQL Cluster
17.3.5. Using High-Speed Interconnects with MySQL Cluster
17.4. MySQL Cluster Programs
17.4.1. ndbd - The MySQL Cluster Data Node Daemon
17.4.2. ndbinfo_select_all - Select From ndbinfo Tables
17.4.3. ndbmtd - The MySQL Cluster Data Node Daemon (Multi-Threaded)
17.4.4. ndb_mgmd - The MySQL Cluster Management Server Daemon
17.4.5. ndb_mgm - The MySQL Cluster Management Client
17.4.6. ndb_config - Extract MySQL Cluster Configuration Information
17.4.7. ndb_cpcd - Automate Testing for NDB Development
17.4.8. ndb_delete_all - Delete All Rows from an NDB Table
17.4.9. ndb_desc - Describe NDB Tables
17.4.10. ndb_drop_index - Drop Index from an NDB Table
17.4.11. ndb_drop_table - Drop an NDB Table
17.4.12. ndb_error_reporter - NDB Error-Reporting Utility
17.4.13. ndb_index_stat - NDB Index Statistics Utility
17.4.14. ndb_print_backup_file - Print NDB Backup File Contents
17.4.15. ndb_print_schema_file - Print NDB Schema File Contents
17.4.16. ndb_print_sys_file - Print NDB System File Contents
17.4.17. ndbd_redo_log_reader - Check and Print Content of Cluster Redo Log
17.4.18. ndb_restore - Restore a MySQL Cluster Backup
17.4.19. ndb_select_all - Print Rows from an NDB Table
17.4.20. ndb_select_count - Print Row Counts for NDB Tables
17.4.21. ndb_show_tables - Display List of NDB Tables
17.4.22. ndb_size.pl - NDBCLUSTER Size Requirement Estimator
17.4.23. ndb_waiter - Wait for MySQL Cluster to Reach a Given Status
17.4.24. Options Common to MySQL Cluster Programs - Options Common to MySQL Cluster Programs
17.5. Management of MySQL Cluster
17.5.1. Summary of MySQL Cluster Start Phases
17.5.2. Commands in the MySQL Cluster Management Client
17.5.3. Online Backup of MySQL Cluster
17.5.4. MySQL Server Usage for MySQL Cluster
17.5.5. Performing a Rolling Restart of a MySQL Cluster
17.5.6. Event Reports Generated in MySQL Cluster
17.5.7. MySQL Cluster Log Messages
17.5.8. MySQL Cluster Single User Mode
17.5.9. Quick Reference: MySQL Cluster SQL Statements
17.5.10. The ndbinfo MySQL Cluster Information Database
17.5.11. MySQL Cluster Security Issues
17.5.12. MySQL Cluster Disk Data Tables
17.5.13. Adding MySQL Cluster Data Nodes Online
17.5.14. Distributed MySQL Privileges for MySQL Cluster
17.5.15. NDB API Statistics Counters and Variables
17.6. MySQL Cluster Replication
17.6.1. MySQL Cluster Replication: Abbreviations and Symbols
17.6.2. General Requirements for MySQL Cluster Replication
17.6.3. Known Issues in MySQL Cluster Replication
17.6.4. MySQL Cluster Replication Schema and Tables
17.6.5. Preparing the MySQL Cluster for Replication
17.6.6. Starting MySQL Cluster Replication (Single Replication Channel)
17.6.7. Using Two Replication Channels for MySQL Cluster Replication
17.6.8. Implementing Failover with MySQL Cluster Replication
17.6.9. MySQL Cluster Backups With MySQL Cluster Replication
17.6.10. MySQL Cluster Replication: Multi-Master and Circular Replication
17.6.11. MySQL Cluster Replication Conflict Resolution
17.7. MySQL Cluster Release Notes

This chapter contains information about MySQL Cluster, which is a high-availability, high-redundancy version of MySQL adapted for the distributed computing environment. Recent releases of MySQL Cluster use version 7 of the NDBCLUSTER storage engine (also known as NDB) to enable running several computers with MySQL servers and other software in a cluster; the latest releases available for production use incorporate NDB version 7.2.

Support for the NDBCLUSTER storage engine is not included in the standard MySQL Server 5.5 binaries built by Oracle. Instead, users of MySQL Cluster binaries from Oracle should upgrade to the most recent binary release of MySQL Cluster for supported platforms-these include RPMs that should work with most Linux distributions. MySQL Cluster users who build from source should use the sources provided for MySQL Cluster. (Locations where the sources can be obtained are listed later in this section.)

This chapter contains information about MySQL Cluster NDB 7.2 releases through 5.5.29-ndb-7.2.10. Currently, the MySQL Cluster NDB 7.2 release series is Generally Available (GA), as is MySQL Cluster NDB 7.1. MySQL Cluster NDB 7.0 and MySQL Cluster NDB 6.3 are previous GA release series; although they are still supported, we recommend that new deployments use MySQL Cluster NDB 7.2. For information about MySQL Cluster NDB 7.1, MySQL Cluster NDB 7.0, and previous versions of MySQL Cluster, see MySQL Cluster NDB 6.1 - 7.1, in the MySQL 5.1 Manual.

Supported Platforms. MySQL Cluster is currently available and supported on a number of platforms. For exact levels of support available for on specific combinations of operating system versions, operating system distributions, and hardware platforms, please refer to http://www.mysql.com/support/supportedplatforms/cluster.html.

Availability. MySQL Cluster binary and source packages are available for supported platforms from http://dev.mysql.com/downloads/cluster/.

MySQL Cluster release numbers. MySQL Cluster follows a somewhat different release pattern from the mainline MySQL Server 5.5 series of releases. In this Manual and other MySQL documentation, we identify these and later MySQL Cluster releases employing a version number that begins with "NDB". This version number is that of the NDBCLUSTER storage engine used in the release, and not of the MySQL server version on which the MySQL Cluster release is based.

Version strings used in MySQL Cluster software. The version string displayed by MySQL Cluster programs uses this format:

mysql-mysql_server_version-ndb-ndb_engine_version

mysql_server_version represents the version of the MySQL Server on which the MySQL Cluster release is based. For all MySQL Cluster NDB 6.x and 7.x releases, this is "5.1". ndb_engine_version is the version of the NDB storage engine used by this release of the MySQL Cluster software. You can see this format used in the mysql client, as shown here:

shell> mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.29-ndb-7.2.10 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> SELECT VERSION()\G*************************** 1. row ***************************VERSION(): 5.5.29-ndb-7.2.101 row in set (0.00 sec)

This version string is also displayed in the output of the SHOW command in the ndb_mgm client:

ndb_mgm> SHOWConnected to Management Server at: localhost:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=1 @10.0.10.6  (5.5.29-ndb-7.2.10, Nodegroup: 0, Master)id=2 @10.0.10.8  (5.5.29-ndb-7.2.10, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=3 @10.0.10.2  (5.5.29-ndb-7.2.10)[mysqld(API)]   2 node(s)id=4 @10.0.10.10  (5.5.29-ndb-7.2.10)id=5 (not connected, accepting connect from any host)

The version string identifies the mainline MySQL version from which the MySQL Cluster release was branched and the version of the NDBCLUSTER storage engine used. For example, the full version string for MySQL Cluster NDB 7.2.4 (the first MySQL Cluster production release based on MySQL Server 5.5) is mysql-5.5.19-ndb-7.2.4. From this we can determine the following:

  • Since the portion of the version string preceding "-ndb-" is the base MySQL Server version, this means that MySQL Cluster NDB 7.2.4 derives from the MySQL 5.5.19, and contains all feature enhancements and bugfixes from MySQL 5.5 up to and including MySQL 5.5.19.

  • Since the portion of the version string following "-ndb-" represents the version number of the NDB (or NDBCLUSTER) storage engine, MySQL Cluster NDB 7.2.4 uses version 7.2.4 of the NDBCLUSTER storage engine.

New MySQL Cluster releases are numbered according to updates in the NDB storage engine, and do not necessarily correspond in a one-to-one fashion with mainline MySQL Server releases. For example, MySQL Cluster NDB 7.2.4 (as previously noted) is based on MySQL 5.5.19, while MySQL Cluster NDB 7.2.0 was based on MySQL 5.1.51 (version string: mysql-5.1.51-ndb-7.2.0).

Compatibility with standard MySQL 5.5 releases. While many standard MySQL schemas and applications can work using MySQL Cluster, it is also true that unmodified applications and database schemas may be slightly incompatible or have suboptimal performance when run using MySQL Cluster (see Section 17.1.6, "Known Limitations of MySQL Cluster"). Most of these issues can be overcome, but this also means that you are very unlikely to be able to switch an existing application datastore-that currently uses, for example, MyISAM or InnoDB-to use the NDB storage engine without allowing for the possibility of changes in schemas, queries, and applications. In addition, the MySQL Server and MySQL Cluster codebases diverge considerably, so that the standard mysqld cannot function as a drop-in replacement for the version of mysqld supplied with MySQL Cluster.

MySQL Cluster development source trees. MySQL Cluster development trees can also be accessed from https://code.launchpad.net/~mysql/:

The MySQL Cluster development sources maintained at https://code.launchpad.net/~mysql/ are licensed under the GPL. For information about obtaining MySQL sources using Bazaar and building them yourself, see Section 2.10.3, "Installing MySQL from a Development Source Tree".

Note

As with MySQL Server 5.5, MySQL Cluster NDB 7.2 is built using CMake.

Currently, MySQL Cluster NDB 7.0, MySQL Cluster NDB 7.1, and MySQL Cluster NDB 7.2 releases are all Generally Available (GA), although we recommend that new deployments use MySQL Cluster NDB 7.2. MySQL Cluster NDB 6.1, MySQL Cluster NDB 6.2, and MySQL Cluster NDB 6.3, are no longer in active development. For an overview of major features added in MySQL Cluster NDB 7.2, see Section 17.1.4, "MySQL Cluster Development History". For an overview of major features added in past MySQL Cluster releases through MySQL Cluster NDB 7.1, see MySQL Cluster Development History.

This chapter represents a work in progress, and its contents are subject to revision as MySQL Cluster continues to evolve. Additional information regarding MySQL Cluster can be found on the MySQL Web site at http://www.mysql.com/products/cluster/.

Additional Resources. More information about MySQL Cluster can be found in the following places:

17.1. MySQL Cluster Overview

MySQL Cluster is a technology that enables clustering of in-memory databases in a shared-nothing system. The shared-nothing architecture enables the system to work with very inexpensive hardware, and with a minimum of specific requirements for hardware or software.

MySQL Cluster is designed not to have any single point of failure. In a shared-nothing system, each component is expected to have its own memory and disk, and the use of shared storage mechanisms such as network shares, network file systems, and SANs is not recommended or supported.

MySQL Cluster integrates the standard MySQL server with an in-memory clustered storage engine called NDB (which stands for "Network DataBase"). In our documentation, the term NDB refers to the part of the setup that is specific to the storage engine, whereas "MySQL Cluster" refers to the combination of one or more MySQL servers with the NDB storage engine.

A MySQL Cluster consists of a set of computers, known as hosts, each running one or more processes. These processes, known as nodes, may include MySQL servers (for access to NDB data), data nodes (for storage of the data), one or more management servers, and possibly other specialized data access programs. The relationship of these components in a MySQL Cluster is shown here:

MySQL Cluster Components

All these programs work together to form a MySQL Cluster (see Section 17.4, "MySQL Cluster Programs". When data is stored by the NDB storage engine, the tables (and table data) are stored in the data nodes. Such tables are directly accessible from all other MySQL servers (SQL nodes) in the cluster. Thus, in a payroll application storing data in a cluster, if one application updates the salary of an employee, all other MySQL servers that query this data can see this change immediately.

Although a MySQL Cluster SQL node uses the mysqld server daemon, it differs in a number of critical respects from the mysqld binary supplied with the MySQL 5.5 distributions, and the two versions of mysqld are not interchangeable.

In addition, a MySQL server that is not connected to a MySQL Cluster cannot use the NDB storage engine and cannot access any MySQL Cluster data.

The data stored in the data nodes for MySQL Cluster can be mirrored; the cluster can handle failures of individual data nodes with no other impact than that a small number of transactions are aborted due to losing the transaction state. Because transactional applications are expected to handle transaction failure, this should not be a source of problems.

Individual nodes can be stopped and restarted, and can then rejoin the system (cluster). Rolling restarts (in which all nodes are restarted in turn) are used in making configuration changes and software upgrades (see Section 17.5.5, "Performing a Rolling Restart of a MySQL Cluster"). Rolling restarts are also used as part of the process of adding new data nodes online (see Section 17.5.13, "Adding MySQL Cluster Data Nodes Online"). For more information about data nodes, how they are organized in a MySQL Cluster, and how they handle and store MySQL Cluster data, see Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions".

Backing up and restoring MySQL Cluster databases can be done using the NDB-native functionality found in the MySQL Cluster management client and the ndb_restore program included in the MySQL Cluster distribution. For more information, see Section 17.5.3, "Online Backup of MySQL Cluster", and Section 17.4.18, "ndb_restore - Restore a MySQL Cluster Backup". You can also use the standard MySQL functionality provided for this purpose in mysqldump and the MySQL server. See Section 4.5.4, "mysqldump - A Database Backup Program", for more information.

MySQL Cluster nodes can use a number of different transport mechanisms for inter-node communications, including TCP/IP using standard 100 Mbps or faster Ethernet hardware. It is also possible to use the high-speed Scalable Coherent Interface (SCI) protocol with MySQL Cluster, although this is not required to use MySQL Cluster. SCI requires special hardware and software; see Section 17.3.5, "Using High-Speed Interconnects with MySQL Cluster", for more about SCI and using it with MySQL Cluster.

17.1.1. MySQL Cluster Core Concepts

NDBCLUSTER (also known as NDB) is an in-memory storage engine offering high-availability and data-persistence features.

The NDBCLUSTER storage engine can be configured with a range of failover and load-balancing options, but it is easiest to start with the storage engine at the cluster level. MySQL Cluster's NDB storage engine contains a complete set of data, dependent only on other data within the cluster itself.

The "Cluster" portion of MySQL Cluster is configured independently of the MySQL servers. In a MySQL Cluster, each part of the cluster is considered to be a node.

Note

In many contexts, the term "node" is used to indicate a computer, but when discussing MySQL Cluster it means a process. It is possible to run multiple nodes on a single computer; for a computer on which one or more cluster nodes are being run we use the term cluster host.

There are three types of cluster nodes, and in a minimal MySQL Cluster configuration, there will be at least three nodes, one of each of these types:

  • Management node: The role of this type of node is to manage the other nodes within the MySQL Cluster, performing such functions as providing configuration data, starting and stopping nodes, running backup, and so forth. Because this node type manages the configuration of the other nodes, a node of this type should be started first, before any other node. An MGM node is started with the command ndb_mgmd.

  • Data node: This type of node stores cluster data. There are as many data nodes as there are replicas, times the number of fragments (see Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions"). For example, with two replicas, each having two fragments, you need four data nodes. One replica is sufficient for data storage, but provides no redundancy; therefore, it is recommended to have 2 (or more) replicas to provide redundancy, and thus high availability. A data node is started with the command ndbd (see Section 17.4.1, "ndbd - The MySQL Cluster Data Node Daemon") or ndbmtd (see Section 17.4.3, "ndbmtd - The MySQL Cluster Data Node Daemon (Multi-Threaded)").

    MySQL Cluster tables are normally stored completely in memory rather than on disk (this is why we refer to MySQL Cluster as an in-memory database). However, some MySQL Cluster data can be stored on disk; see Section 17.5.12, "MySQL Cluster Disk Data Tables", for more information.

  • SQL node: This is a node that accesses the cluster data. In the case of MySQL Cluster, an SQL node is a traditional MySQL server that uses the NDBCLUSTER storage engine. An SQL node is a mysqld process started with the --ndbcluster and --ndb-connectstring options, which are explained elsewhere in this chapter, possibly with additional MySQL server options as well.

    An SQL node is actually just a specialized type of API node, which designates any application which accesses MySQL Cluster data. Another example of an API node is the ndb_restore utility that is used to restore a cluster backup. It is possible to write such applications using the NDB API. For basic information about the NDB API, see Getting Started with the NDB API.

Important

It is not realistic to expect to employ a three-node setup in a production environment. Such a configuration provides no redundancy; to benefit from MySQL Cluster's high-availability features, you must use multiple data and SQL nodes. The use of multiple management nodes is also highly recommended.

For a brief introduction to the relationships between nodes, node groups, replicas, and partitions in MySQL Cluster, see Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions".

Configuration of a cluster involves configuring each individual node in the cluster and setting up individual communication links between nodes. MySQL Cluster is currently designed with the intention that data nodes are homogeneous in terms of processor power, memory space, and bandwidth. In addition, to provide a single point of configuration, all configuration data for the cluster as a whole is located in one configuration file.

The management server manages the cluster configuration file and the cluster log. Each node in the cluster retrieves the configuration data from the management server, and so requires a way to determine where the management server resides. When interesting events occur in the data nodes, the nodes transfer information about these events to the management server, which then writes the information to the cluster log.

In addition, there can be any number of cluster client processes or applications. These include standard MySQL clients, NDB-specific API programs, and management clients. These are described in the next few paragraphs.

Standard MySQL clients. MySQL Cluster can be used with existing MySQL applications written in PHP, Perl, C, C++, Java, Python, Ruby, and so on. Such client applications send SQL statements to and receive responses from MySQL servers acting as MySQL Cluster SQL nodes in much the same way that they interact with standalone MySQL servers.

MySQL clients using a MySQL Cluster as a data source can be modified to take advantage of the ability to connect with multiple MySQL servers to achieve load balancing and failover. For example, Java clients using Connector/J 5.0.6 and later can use jdbc:mysql:loadbalance:// URLs (improved in Connector/J 5.1.7) to achieve load balancing transparently; for more information about using Connector/J with MySQL Cluster, see Using Connector/J with MySQL Cluster.

NDB client programs. Client programs can be written that access MySQL Cluster data directly from the NDBCLUSTER storage engine, bypassing any MySQL Servers that may connected to the cluster, using the NDB API, a high-level C++ API. Such applications may be useful for specialized purposes where an SQL interface to the data is not needed. For more information, see The NDB API.

NDB-specific Java applications can also be written for MySQL Cluster using the MySQL Cluster Connector for Java. This MySQL Cluster Connector includes ClusterJ, a high-level database API similar to object-relational mapping persistence frameworks such as Hibernate and JPA that connect directly to NDBCLUSTER, and so does not require access to a MySQL Server. Support is also provided in MySQL Cluster NDB 7.1 and later for ClusterJPA, an OpenJPA implementation for MySQL Cluster that leverages the strengths of ClusterJ and JDBC; ID lookups and other fast operations are performed using ClusterJ (bypassing the MySQL Server), while more complex queries that can benefit from MySQL's query optimizer are sent through the MySQL Server, using JDBC. See Java and MySQL Cluster, and The ClusterJ API and Data Object Model, for more information.

The Memcache API for MySQL Cluster, implemented as the loadable ndbmemcache storage engine for memcached version 1.6 and later, is available beginning with MySQL Cluster NDB 7.2.2. This API can be used to provide a persistent MySQL Cluster data store, accessed using the memcache protocol.

The standard memcached caching engine is included in the MySQL Cluster NDB 7.2 distribution (7.2.2 and later). Each memcached server has direct access to data stored in MySQL Cluster, but is also able to cache data locally and to serve (some) requests from this local cache.

For more information, see ndbmemcache-Memcache API for MySQL Cluster.

Management clients. These clients connect to the management server and provide commands for starting and stopping nodes gracefully, starting and stopping message tracing (debug versions only), showing node versions and status, starting and stopping backups, and so on. An example of this type of program is the ndb_mgm management client supplied with MySQL Cluster (see Section 17.4.5, "ndb_mgm - The MySQL Cluster Management Client"). Such applications can be written using the MGM API, a C-language API that communicates directly with one or more MySQL Cluster management servers. For more information, see The MGM API.

Oracle also makes available MySQL Cluster Manager, which provides an advanced command-line interface simplifying many complex MySQL Cluster management tasks, such restarting a MySQL Cluster with a large number of nodes. The MySQL Cluster Manager client also supports commands for getting and setting the values of most node configuration parameters as well as mysqld server options and variables relating to MySQL Cluster. MySQL Cluster Manager 1.1 provides support for adding data nodes online. See the MySQL Cluster Manager User Manual, for more information.

Event logs. MySQL Cluster logs events by category (startup, shutdown, errors, checkpoints, and so on), priority, and severity. A complete listing of all reportable events may be found in Section 17.5.6, "Event Reports Generated in MySQL Cluster". Event logs are of the two types listed here:

  • Cluster log: Keeps a record of all desired reportable events for the cluster as a whole.

  • Node log: A separate log which is also kept for each individual node.

Note

Under normal circumstances, it is necessary and sufficient to keep and examine only the cluster log. The node logs need be consulted only for application development and debugging purposes.

Checkpoint. Generally speaking, when data is saved to disk, it is said that a checkpoint has been reached. More specific to MySQL Cluster, a checkpoint is a point in time where all committed transactions are stored on disk. With regard to the NDB storage engine, there are two types of checkpoints which work together to ensure that a consistent view of the cluster's data is maintained. These are shown in the following list:

  • Local Checkpoint (LCP): This is a checkpoint that is specific to a single node; however, LCP's take place for all nodes in the cluster more or less concurrently. An LCP involves saving all of a node's data to disk, and so usually occurs every few minutes. The precise interval varies, and depends upon the amount of data stored by the node, the level of cluster activity, and other factors.

  • Global Checkpoint (GCP): A GCP occurs every few seconds, when transactions for all nodes are synchronized and the redo-log is flushed to disk.

17.1.2. MySQL Cluster Nodes, Node Groups, Replicas, and Partitions

This section discusses the manner in which MySQL Cluster divides and duplicates data for storage.

A number of concepts central to an understanding of this topic are discussed in the next few paragraphs.

(Data) Node. An ndbd process, which stores a replica -that is, a copy of the partition (see below) assigned to the node group of which the node is a member.

Each data node should be located on a separate computer. While it is also possible to host multiple ndbd processes on a single computer, such a configuration is not supported.

It is common for the terms "node" and "data node" to be used interchangeably when referring to an ndbd process; where mentioned, management nodes (ndb_mgmd processes) and SQL nodes (mysqld processes) are specified as such in this discussion.

Node Group. A node group consists of one or more nodes, and stores partitions, or sets of replicas (see next item).

The number of node groups in a MySQL Cluster is not directly configurable; it is a function of the number of data nodes and of the number of replicas (NoOfReplicas configuration parameter), as shown here:

[number_of_node_groups] = number_of_data_nodes / NoOfReplicas

Thus, a MySQL Cluster with 4 data nodes has 4 node groups if NoOfReplicas is set to 1 in the config.ini file, 2 node groups if NoOfReplicas is set to 2, and 1 node group if NoOfReplicas is set to 4. Replicas are discussed later in this section; for more information about NoOfReplicas, see Section 17.3.2.6, "Defining MySQL Cluster Data Nodes".

Note

All node groups in a MySQL Cluster must have the same number of data nodes.

You can add new node groups (and thus new data nodes) online, to a running MySQL Cluster; see Section 17.5.13, "Adding MySQL Cluster Data Nodes Online", for more information.

Partition. This is a portion of the data stored by the cluster. There are as many cluster partitions as nodes participating in the cluster. Each node is responsible for keeping at least one copy of any partitions assigned to it (that is, at least one replica) available to the cluster.

A replica belongs entirely to a single node; a node can (and usually does) store several replicas.

NDB and user-defined partitioning. MySQL Cluster normally partitions NDBCLUSTER tables automatically. However, in MySQL 5.1 and later MySQL Cluster releases, it is possible to employ user-defined partitioning with NDBCLUSTER tables. This is subject to the following limitations:

  1. Only KEY and LINEAR KEY partitioning schemes can be used with NDBCLUSTER tables.

  2. When using ndbd, the maximum number of partitions that may be defined explicitly for any NDBCLUSTER table is 8 * [number of node groups]. (The number of node groups in a MySQL Cluster is determined as discussed previously in this section.)

    When using ndbmtd, this maximum is also affected by the number of local query handler threads, which is determined by the value of the MaxNoOfExecutionThreads configuration parameter. In such cases, the maxmimum number of partitions that may be defined explicitly for an NDB table is equal to 4 * MaxNoOfExecutionThreads * [number of node groups].

    See Section 17.4.3, "ndbmtd - The MySQL Cluster Data Node Daemon (Multi-Threaded)", for more information.

For more information relating to MySQL Cluster and user-defined partitioning, see Section 17.1.6, "Known Limitations of MySQL Cluster", and Section 18.5.2, "Partitioning Limitations Relating to Storage Engines".

Replica. This is a copy of a cluster partition. Each node in a node group stores a replica. Also sometimes known as a partition replica. The number of replicas is equal to the number of nodes per node group.

The following diagram illustrates a MySQL Cluster with four data nodes, arranged in two node groups of two nodes each; nodes 1 and 2 belong to node group 0, and nodes 3 and 4 belong to node group 1. Note that only data (ndbd) nodes are shown here; although a working cluster requires an ndb_mgm process for cluster management and at least one SQL node to access the data stored by the cluster, these have been omitted in the figure for clarity.

A MySQL Cluster, with 2 node groups having 2 nodes each

The data stored by the cluster is divided into four partitions, numbered 0, 1, 2, and 3. Each partition is stored-in multiple copies-on the same node group. Partitions are stored on alternate node groups as follows:

  • Partition 0 is stored on node group 0; a primary replica (primary copy) is stored on node 1, and a backup replica (backup copy of the partition) is stored on node 2.

  • Partition 1 is stored on the other node group (node group 1); this partition's primary replica is on node 3, and its backup replica is on node 4.

  • Partition 2 is stored on node group 0. However, the placing of its two replicas is reversed from that of Partition 0; for Partition 2, the primary replica is stored on node 2, and the backup on node 1.

  • Partition 3 is stored on node group 1, and the placement of its two replicas are reversed from those of partition 1. That is, its primary replica is located on node 4, with the backup on node 3.

What this means regarding the continued operation of a MySQL Cluster is this: so long as each node group participating in the cluster has at least one node operating, the cluster has a complete copy of all data and remains viable. This is illustrated in the next diagram.

Nodes required to keep a 2x2 cluster viable

In this example, where the cluster consists of two node groups of two nodes each, any combination of at least one node in node group 0 and at least one node in node group 1 is sufficient to keep the cluster "alive" (indicated by arrows in the diagram). However, if both nodes from either node group fail, the remaining two nodes are not sufficient (shown by the arrows marked out with an X); in either case, the cluster has lost an entire partition and so can no longer provide access to a complete set of all cluster data.

17.1.3. MySQL Cluster Hardware, Software, and Networking Requirements

One of the strengths of MySQL Cluster is that it can be run on commodity hardware and has no unusual requirements in this regard, other than for large amounts of RAM, due to the fact that all live data storage is done in memory. (It is possible to reduce this requirement using Disk Data tables-see Section 17.5.12, "MySQL Cluster Disk Data Tables", for more information about these.) Naturally, multiple and faster CPUs can enhance performance. Memory requirements for other MySQL Cluster processes are relatively small.

The software requirements for MySQL Cluster are also modest. Host operating systems do not require any unusual modules, services, applications, or configuration to support MySQL Cluster. For supported operating systems, a standard installation should be sufficient. The MySQL software requirements are simple: all that is needed is a production release of MySQL Cluster. It is not strictly necessary to compile MySQL yourself merely to be able to use MySQL Cluster. We assume that you are using the binaries appropriate to your platform, available from the MySQL Cluster software downloads page at http://dev.mysql.com/downloads/cluster/.

For communication between nodes, MySQL Cluster supports TCP/IP networking in any standard topology, and the minimum expected for each host is a standard 100 Mbps Ethernet card, plus a switch, hub, or router to provide network connectivity for the cluster as a whole. We strongly recommend that a MySQL Cluster be run on its own subnet which is not shared with machines not forming part of the cluster for the following reasons:

  • Security. Communications between MySQL Cluster nodes are not encrypted or shielded in any way. The only means of protecting transmissions within a MySQL Cluster is to run your MySQL Cluster on a protected network. If you intend to use MySQL Cluster for Web applications, the cluster should definitely reside behind your firewall and not in your network's De-Militarized Zone (DMZ) or elsewhere.

    See Section 17.5.11.1, "MySQL Cluster Security and Networking Issues", for more information.

  • Efficiency. Setting up a MySQL Cluster on a private or protected network enables the cluster to make exclusive use of bandwidth between cluster hosts. Using a separate switch for your MySQL Cluster not only helps protect against unauthorized access to MySQL Cluster data, it also ensures that MySQL Cluster nodes are shielded from interference caused by transmissions between other computers on the network. For enhanced reliability, you can use dual switches and dual cards to remove the network as a single point of failure; many device drivers support failover for such communication links.

Network communication and latency. MySQL Cluster requires communication between data nodes and API nodes (including SQL nodes), as well as between data nodes and other data nodes, to execute queries and updates. Communication latency between these processes can directly affect the observed performance and latency of user queries. In addition, to maintain consistency and service despite the silent failure of nodes, MySQL Cluster uses heartbeating and timeout mechanisms which treat an extended loss of communication from a node as node failure. This can lead to reduced redundancy. Recall that, to maintain data consistency, a MySQL Cluster shuts down when the last node in a node group fails. Thus, to avoid increasing the risk of a forced shutdown, breaks in communication between nodes should be avoided wherever possible.

The failure of a data or API node results in the abort of all uncommitted transactions involving the failed node. Data node recovery requires synchronization of the failed node's data from a surviving data node, and re-establishment of disk-based redo and checkpoint logs, before the data node returns to service. This recovery can take some time, during which the Cluster operates with reduced redundancy.

Heartbeating relies on timely generation of heartbeat signals by all nodes. This may not be possible if the node is overloaded, has insufficient machine CPU due to sharing with other programs, or is experiencing delays due to swapping. If heartbeat generation is sufficiently delayed, other nodes treat the node that is slow to respond as failed.

This treatment of a slow node as a failed one may or may not be desirable in some circumstances, depending on the impact of the node's slowed operation on the rest of the cluster. When setting timeout values such as HeartbeatIntervalDbDb and HeartbeatIntervalDbApi for MySQL Cluster, care must be taken care to achieve quick detection, failover, and return to service, while avoiding potentially expensive false positives.

Where communication latencies between data nodes are expected to be higher than would be expected in a LAN environment (on the order of 100 �s), timeout parameters must be increased to ensure that any allowed periods of latency periods are well within configured timeouts. Increasing timeouts in this way has a corresponding effect on the worst-case time to detect failure and therefore time to service recovery.

LAN environments can typically be configured with stable low latency, and such that they can provide redundancy with fast failover. Individual link failures can be recovered from with minimal and controlled latency visible at the TCP level (where MySQL Cluster normally operates). WAN environments may offer a range of latencies, as well as redundancy with slower failover times. Individual link failures may require route changes to propagate before end-to-end connectivity is restored. At the TCP level this can appear as large latencies on individual channels. The worst-case observed TCP latency in these scenarios is related to the worst-case time for the IP layer to reroute around the failures.

SCI support. It is also possible to use the high-speed Scalable Coherent Interface (SCI) with MySQL Cluster, but this is not a requirement. See Section 17.3.5, "Using High-Speed Interconnects with MySQL Cluster", for more about this protocol and its use with MySQL Cluster.

17.1.4. MySQL Cluster Development History

In this section, we discuss changes in the implementation of MySQL Cluster in MySQL MySQL Cluster NDB 7.2, as compared to MySQL Cluster NDB 7.1 and earlier releases. Changes and features most likely to be of interest are shown in the following table:

MySQL Cluster NDB 7.2
MySQL Cluster NDB 7.2.1 and later MySQL Cluster NDB 7.2 releases are based on MySQL 5.5. For more information about new features in MySQL Server 5.5, see Section 1.4, "What Is New in MySQL 5.5".
Version 2 binary log row events, to provide support for improvements in MySQL Cluster Replication conflict detection (see next item). A given mysqld can be made to use Version 1 or Version 2 binary logging row events with the --log-bin-use-v1-row-events option.
Two new "primary wins" conflict detection and resolution functions NDB$EPOCH() and NDB$EPOCH_TRANS() for use in replication setups with 2 MySQL Clusters. For more information, see Section 17.6, "MySQL Cluster Replication".
Distribution of MySQL users and privileges across MySQL Cluster SQL nodes is now supported-see Section 17.5.14, "Distributed MySQL Privileges for MySQL Cluster".
Improved support for distributed pushed-down joins, which greatly improve performance for many joins that can be executed in parallel on the data nodes.
Default values for a number of data node configuration parameters such as HeartbeatIntervalDbDb and ArbitrationTimeout have been improved.
Support for the Memcache API using the loadable ndbmemcache storageengine. See ndbmemcache-Memcache API for MySQL Cluster.

This section contains information about MySQL Cluster NDB 7.2 releases through 5.5.29-ndb-7.2.10, which is currently available for use in production beginning with MySQL Cluster NDB 7.2.4. MySQL Cluster NDB 7.1, MySQL Cluster NDB 7.0, and MySQL Cluster NDB 6.3 are previous GA release series; although these are still supported, we recommend that new deployments use MySQL Cluster NDB 7.2. For information about MySQL Cluster NDB 7.1 and previous releases, see MySQL Cluster NDB 6.1 - 7.1, in the MySQL 5.1 Manual.

17.1.4.1. MySQL Cluster Development in MySQL Cluster NDB 7.2

The following improvements to MySQL Cluster have been made in MySQL Cluster NDB 7.2:

  • Based on MySQL Server 5.5. Previous MySQL Cluster release series, including MySQL Cluster NDB 7.1, used MySQL 5.1 as a base. Beginning with MySQL Cluster NDB 7.2.1, MySQL Cluster NDB 7.2 is based on MySQL Server 5.5, so that MySQL Cluster users can benefit from MySQL 5.5's improvements in scalability and performance monitoring. As with MySQL 5.5, MySQL Cluster NDB 7.2.1 and later use CMake for configuring and building from source inh place of GNU autotools (used in MySQL 5.1 and MySQL Cluster releases based on MySQL 5.1). For more information about changes and improvements in MySQL 5.5, see Section 1.4, "What Is New in MySQL 5.5".

  • Conflict detection using GCI Reflection. MySQL Cluster Replication implements a new "primary wins" conflict detection and resolution mechanism. GCI Reflection applies in two-cluster circulation "active-active" replication setups, tracking the order in which changes are applied on the MySQL Cluster designated as primary relative to changes originating on the other MySQL Cluster (referred to as the secondary). This relative ordering is used to determine whether changes originating on the slave are concurrent with any changes that originate locally, and are therefore potentially in conflict. Two new conflict detection functions are added: When using NDB$EPOCH(), rows that are out of sync on the secondary are realigned with those on the primary; with NDB$EPOCH_TRANS(), this realignment is applied to transactions. For more information, see Section 17.6.11, "MySQL Cluster Replication Conflict Resolution".

  • Version 2 binary log row events. A new format for binary log row events, known as Version 2 binary log row events, provides support for improvements in MySQL Cluster Replication conflict detection (see previous item) and is intended to facilitate further improvements in MySQL Replication. You can cause a given mysqld use Version 1 or Version 2 binary logging row events with the --log-bin-use-v1-row-events option. For backwards compatibility, Version 2 binary log row events are also available in MySQL Cluster NDB 7.0 (7.0.27 and later) and MySQL Cluster NDB 7.1 (7.1.16 and later). However, MySQL Cluster NDB 7.0 and MySQL Cluster NDB 7.1 continue to use Version 1 binary log row events as the default, whereas the default in MySQL Cluster NDB 7.2.1 and later is use Version 2 row events for binary logging.

  • Distribution of MySQL users and privileges. Automatic distribution of MySQL users and privileges across all SQL nodes in a given MySQL Cluster is now supported. To enable this support, you must first import an SQL script share/mysql/ndb_dist_priv.sql that is included with the MySQL Cluster NDB 7.2 distribution. This script creates several stored procedures which you can use to enable privilege distribution and perform related tasks.

    When a new MySQL Server joins a MySQL Cluster where privilege distribution is in effect, it also participates in the privilege distribution automatically.

    Once privilege distribution is enabled, all changes to the grant tables made on any mysqld attached to the cluster are immediately available on any other attached MySQL Servers. This is true whether the changes are made using CREATE USER, GRANT, or any of the other statements described elsewhere in this Manual (see Section 13.7.1, "Account Management Statements".) This includes privileges relating to stored routines and views; however, automatic distribution of the views or stored routines themselves is not currently supported.

    For more information, see Section 17.5.14, "Distributed MySQL Privileges for MySQL Cluster".

  • Distributed pushed-down joins. Many joins can now be pushed down to the NDB kernel for processing on MySQL Cluster data nodes. Previously, a join was handled in MySQL Cluster by means of repeated accesses of NDB by the SQL node; however, when pushed-down joins are enabled, a pushable join is sent in its entirety to the data nodes, where it can be distributed among the data nodes and executed in parallel on multiple copies of the data, with a single, merged result being returned to mysqld. This can reduce greatly the number of round trips between an SQL node and the data nodes required to handle such a join, leading to greatly improved performance of join processing.

    It is possible to determine when joins can be pushed down to the data nodes by examining the join with EXPLAIN. A number of new system status variables (Ndb_pushed_queries_defined, Ndb_pushed_queries_dropped, Ndb_pushed_queries_executed, and Ndb_pushed_reads) and additions to the counters table (in the ndbinfo information database) can also be helpful in determining when and how well joins are being pushed down.

    More information and examples are available in the description of the ndb_join_pushdown server system variable. See also the description of the status variables referenced in the previous paragraph, as well as Section 17.5.10.7, "The ndbinfo counters Table".

  • Improved default values for data node configuration parameters. In order to provide more resiliency to environmental issues and better handling of some potential failure scenarios, and to perform more reliably with increases in memory and other resource requirements brought about by recent improvements in join handling by NDB, the default values for a number of MySQL Cluster data node configuration parameters have been changed. The parameters and changes are described in the following list:

    In addition, the value computed for MaxNoOfLocalScans when this parameter is not set in config.ini has been increased by a factor of 4.

  • Fail-fast data nodes. Beginning with MySQL Cluster NDB 7.2.1, data nodes handle corrupted tuples in a fail-fast manner by default. This is a change from previous versions of MySQL Cluster where this behavior had to be enabled explicitly by enabling the CrashOnCorruptedTuple configuration parameter. In MySQL Cluster NDB 7.2.1 and later, this parameter is enabled by default and must be explicitly disabled, in which case data nodes merely log a warning whenever they detect a corrupted tuple.

  • Memcache API support (ndbmemcache). The Memcached server is a distributed in-memory caching server that uses a simple text-based protocol. It is often employed with key-value stores. The Memcache API for MySQL Cluster, available beginning with MySQL Cluster NDB 7.2.2, is implemented as a loadable storage engine for memcached version 1.6 and later. This API can be used to access a persistent MySQL Cluster data store employing the memcache protocol. It is also possible for the memcached server to provide a strictly defined interface to existing MySQL Cluster tables.

    Each memcache server can both cache data locally and access data stored in MySQL Cluster directly. Caching policies are configurable. For more information, see ndbmemcache-Memcache API for MySQL Cluster, in the MySQL Cluster API Developers Guide.

  • Rows per partition limit removed. Previously it was possible to store a maximum of 46137488 rows in a single MySQL Cluster partition-that is, per data node. Beginning with MySQL Cluster NDB 7.2.9, this limitation has been lifted, and there is no longer any practical upper limit to this number.

17.1.5. MySQL Server using InnoDB Compared with MySQL Cluster

MySQL Server offers a number of choices in storage engines. Since both NDBCLUSTER and InnoDB can serve as transactional MySQL storage engines, users of MySQL Server sometimes become interested in MySQL Cluster. They see NDB as a possible alternative or upgrade to the default InnoDB storage engine in MySQL 5.5. While NDB and InnoDB share common characteristics, there are differences in architecture and implementation, so that some existing MySQL Server applications and usage scenarios can be a good fit for MySQL Cluster, but not all of them.

In this section, we discuss and compare some characteristics of the NDB storage engine used by MySQL Cluster NDB 7.2 with InnoDB used in MySQL 5.5. The next few sections provide a technical comparison. In many instances, decisions about when and where to use MySQL Cluster must be made on a case-by-case basis, taking all factors into consideration. While it is beyond the scope of this documentation to provide specifics for every conceivable usage scenario, we also attempt to offer some very general guidance on the relative suitability of some common types of applications for NDB as opposed to InnoDB backends.

Recent MySQL Cluster NDB 7.2 releases use a mysqld based on MySQL 5.5, including support for InnoDB 1.1. While it is possible to use InnoDB tables with MySQL Cluster, such tables are not clustered. It is also not possible to use programs or libraries from a MySQL Cluster NDB 7.2 distribution with MySQL Server 5.5, or the reverse.

While it is also true that some types of common business applications can be run either on MySQL Cluster or on MySQL Server (most likely using the InnoDB storage engine), there are some important architectural and implementation differences. Section 17.1.5.1, "Differences Between the NDB and InnoDB Storage Engines", provides a summary of the these differences. Due to the differences, some usage scenarios are clearly more suitable for one engine or the other; see Section 17.1.5.2, "NDB and InnoDB Workloads". This in turn has an impact on the types of applications that better suited for use with NDB or InnoDB. See Section 17.1.5.3, "NDB and InnoDB Feature Usage Summary", for a comparison of the relative suitability of each for use in common types of database applications.

For information about the relative characteristics of the NDB and MEMORY storage engines, see When to Use MEMORY or MySQL Cluster.

See Chapter 14, Storage Engines, for additional information about MySQL storage engines.

17.1.5.1. Differences Between the NDB andInnoDB Storage Engines

The MySQL Cluster NDB storage engine is implemented using a distributed, shared-nothing architecture, which causes it to behave differently from InnoDB in a number of ways. For those unaccustomed to working with NDB, unexpected behaviors can arise due to its distributed nature with regard to transactions, foreign keys, table limits, and other characteristics. These are shown in the following table:

Feature

InnoDB 1.1

MySQL Cluster NDB 7.2

MySQL Server Version

5.5

5.5

InnoDB Version

InnoDB 1.1

InnoDB 1.1

MySQL Cluster Version

N/A

NDB 7.2

Storage Limits

64TB

3TB

(Practical upper limit based on 48 data nodes with 64GB RAM each; can be increased with disk-based data and BLOBs)

Foreign Keys

Yes

No

(Ignored, as with MyISAM)

Note

A MySQL Cluster NDB 7.3 Development Milestone Release that includes a preview of foreign key support for the InnoDB storage engine is now available. See https://dev.mysql.com/tech-resources/articles/cluster-7.3-dmr.html, for more information.

Transactions

All standard types

READ COMMITTED

MVCC

Yes

No

Data Compression

Yes

No

(MySQL Cluster checkpoint and backup files can be compressed)

Large Row Support (> 14K)

Supported for VARBINARY, VARCHAR, BLOB, and TEXT columns

Supported for BLOB and TEXT columns only

(Using these types to store very large amounts of data can lower MySQL Cluster performance)

Replication Support

Asynchronous and semi-synchronous replication using MySQL Replication

Automatic synchronous replication within a MySQL Cluster.

Asynchronous replication between MySQL Clusters, using MySQL Replication

Scaleout for Read Operations

Yes (MySQL Replication)

Yes (Automatic partitioning in MySQL Cluster; MySQL Replication)

Scaleout for Write Operations

Requires application-level partitioning (sharding)

Yes (Automatic partitioning in MySQL Cluster is transparent to applications)

High Availability (HA)

Requires additional software

Yes (Designed for 99.999% uptime)

Node Failure Recovery and Failover

Requires additional software

Automatic

(Key element in MySQL Cluster architecture)

Time for Node Failure Recovery

30 seconds or longer

Typically < 1 second

Real-Time Performance

No

Yes

In-Memory Tables

No

Yes

(Some data can optionally be stored on disk; both in-memory and disk data storage are durable)

NoSQL Access to Storage Engine

Native memcached interface in development (see the MySQL Dev Zone article NoSQL to MySQL with Memcached)

Yes

Multiple APIs, including Memcached, Node.js/JavaScript, Java, JPA, C++, and HTTP/REST

Concurrent and Parallel Writes

Not supported

Up to 48 writers, optimized for concurrent writes

Conflict Detection and Resolution (Multiple Replication Masters)

No

Yes

Hash Indexes

No

Yes

Online Addition of Nodes

Read-only replicas using MySQL Replication

Yes (all node types)

Online Upgrades

No

Yes

Online Schema Modifications

No

Yes, as part of the MySQL 5.6 Release Candidate. See https://dev.mysql.com/tech-resources/articles/mysql-5.6-rc.html, for more information

17.1.5.2. NDB and InnoDBWorkloads

MySQL Cluster has a range of unique attributes that make it ideal to serve applications requiring high availability, fast failover, high throughput, and low latency. Due to its distributed architecture and multi-node implementation, MySQL Cluster also has specific constraints that may keep some workloads from performing well. A number of major differences in behavior between the NDB and InnoDB storage engines with regard to some common types of database-driven application workloads are shown in the following table::

Workload

InnoDB

MySQL Cluster (NDB)

High-Volume OLTP Applications

Yes

Yes

DSS Applications (data marts, analytics)

Yes

Limited (Join operations across OLTP datasets not exceeding 3TB in size)

Custom Applications

Yes

Yes

Packaged Applications

Yes

Limited (should be mostly primary key access)

Note

A MySQL Cluster NDB 7.3 Development Milestone Release that includes a preview of foreign key support for the InnoDB storage engine is now available. See https://dev.mysql.com/tech-resources/articles/cluster-7.3-dmr.html, for more information.

In-Network Telecoms Applications (HLR, HSS, SDP)

No

Yes

Session Management and Caching

Yes

Yes

E-Commerce Applications

Yes

Yes

User Profile Management, AAA Protocol

Yes

Yes

17.1.5.3. NDB and InnoDBFeature Usage Summary

When comparing application feature requirements to the capabilities of InnoDB with NDB, some are clearly more compatible with one storage engine than the other. For example, since NDB does not support foreign keys, an application that requires them and cannot be re-engineered to remove this requirement is likely not to be a good match for MySQL Cluster.

Note

A MySQL Cluster NDB 7.3 Development Milestone Release that includes a preview of foreign key support for the InnoDB storage engine is now available. See https://dev.mysql.com/tech-resources/articles/cluster-7.3-dmr.html, for more information.

The following table shows required supported features for applications according to which of these two storage engines each of them is usually better suited:

Preferred application requirements for InnoDB

Preferred application requirements for NDB

17.1.6. Known Limitations of MySQL Cluster

In the sections that follow, we discuss known limitations in current releases of MySQL Cluster as compared with the features available when using the MyISAM and InnoDB storage engines. If you check the "Cluster" category in the MySQL bugs database at http://bugs.mysql.com, you can find known bugs in the following categories under "MySQL Server:" in the MySQL bugs database at http://bugs.mysql.com, which we intend to correct in upcoming releases of MySQL Cluster:

  • MySQL Cluster

  • Cluster Direct API (NDBAPI)

  • Cluster Disk Data

  • Cluster Replication

  • ClusterJ

This information is intended to be complete with respect to the conditions just set forth. You can report any discrepancies that you encounter to the MySQL bugs database using the instructions given in Section 1.7, "How to Report Bugs or Problems". If we do not plan to fix the problem in MySQL Cluster NDB 6.X or 7.X, we will add it to the list.

See Section 17.1.6.11, "Previous MySQL Cluster Issues Resolved in MySQL 5.1, MySQL Cluster NDB 6.x, and MySQL Cluster NDB 7.x" for a list of issues in MySQL Cluster in MySQL 5.1 that have been resolved in the current version.

Note

Limitations and other issues specific to MySQL Cluster Replication are described in Section 17.6.3, "Known Issues in MySQL Cluster Replication".

17.1.6.1. Noncompliance with SQL Syntax in MySQL Cluster

Some SQL statements relating to certain MySQL features produce errors when used with NDB tables, as described in the following list:

  • Temporary tables. Temporary tables are not supported. Trying either to create a temporary table that uses the NDB storage engine or to alter an existing temporary table to use NDB fails with the error Table storage engine 'ndbcluster' does not support the create option 'TEMPORARY'.

  • Indexes and keys in NDB tables. Keys and indexes on MySQL Cluster tables are subject to the following limitations:

    • Column width. Attempting to create an index on an NDB table column whose width is greater than 3072 bytes succeeds, but only the first 3072 bytes are actually used for the index. In such cases, a warning Specified key was too long; max key length is 3072 bytes is issued, and a SHOW CREATE TABLE statement shows the length of the index as 3072.

    • TEXT and BLOB columns. You cannot create indexes on NDB table columns that use any of the TEXT or BLOB data types.

    • FULLTEXT indexes. The NDB storage engine does not support FULLTEXT indexes, which are possible for MyISAM tables only.

      However, you can create indexes on VARCHAR columns of NDB tables.

    • USING HASH keys and NULL. Using nullable columns in unique keys and primary keys means that queries using these columns are handled as full table scans. To work around this issue, make the column NOT NULL, or re-create the index without the USING HASH option.

    • Prefixes. There are no prefix indexes; only entire columns can be indexed. (The size of an NDB column index is always the same as the width of the column in bytes, up to and including 3072 bytes, as described earlier in this section. Also see Section 17.1.6.6, "Unsupported or Missing Features in MySQL Cluster", for additional information.)

    • BIT columns. A BIT column cannot be a primary key, unique key, or index, nor can it be part of a composite primary key, unique key, or index.

    • AUTO_INCREMENT columns. Like other MySQL storage engines, the NDB storage engine can handle a maximum of one AUTO_INCREMENT column per table. However, in the case of a Cluster table with no explicit primary key, an AUTO_INCREMENT column is automatically defined and used as a "hidden" primary key. For this reason, you cannot define a table that has an explicit AUTO_INCREMENT column unless that column is also declared using the PRIMARY KEY option. Attempting to create a table with an AUTO_INCREMENT column that is not the table's primary key, and using the NDB storage engine, fails with an error.

  • MySQL Cluster and geometry data types. Geometry data types (WKT and WKB) are supported for NDB tables. However, spatial indexes are not supported.

  • Character sets and binary log files. Currently, the ndb_apply_status and ndb_binlog_index tables are created using the latin1 (ASCII) character set. Because names of binary logs are recorded in this table, binary log files named using non-Latin characters are not referenced correctly in these tables. This is a known issue, which we are working to fix. (Bug #50226)

    To work around this problem, use only Latin-1 characters when naming binary log files or setting any the --basedir, --log-bin, or --log-bin-index options.

  • Creating NDBCLUSTER tables with user-defined partitioning. Support for user-defined partitioning for MySQL Cluster in MySQL 5.1 (including MySQL Cluster NDB 6.X and 7.X through 7.1) is restricted to [LINEAR] KEY partitioning. Beginning with MySQL 5.1.12, using any other partitioning type with ENGINE=NDB or ENGINE=NDBCLUSTER in a CREATE TABLE statement results in an error.

    Default partitioning scheme. As of MySQL 5.1.6, all MySQL Cluster tables are by default partitioned by KEY using the table's primary key as the partitioning key. If no primary key is explicitly set for the table, the "hidden" primary key automatically created by the NDBCLUSTER storage engine is used instead. For additional discussion of these and related issues, see Section 18.2.5, "KEY Partitioning".

    CREATE TABLE and ALTER TABLE statements that would cause a user-partitioned NDBCLUSTER table not to meet either or both of the following two requirements are not permitted, and fail with an error:

    1. The table must have an explicit primary key.

    2. All columns listed in the table's partitioning expression must be part of the primary key.

    Exception. If a user-partitioned NDBCLUSTER table is created using an empty column-list (that is, using PARTITION BY [LINEAR] KEY()), then no explicit primary key is required.

    Maximum number of partitions for NDBCLUSTER tables. The maximum number of partitions that can defined for a NDBCLUSTER table when employing user-defined partitioning is 8 per node group. (See Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions", for more information about MySQL Cluster node groups.

    DROP PARTITION not supported. It is not possible to drop partitions from NDB tables using ALTER TABLE ... DROP PARTITION. The other partitioning extensions to ALTER TABLE-ADD PARTITION, REORGANIZE PARTITION, and COALESCE PARTITION-are supported for Cluster tables, but use copying and so are not optimized. See Section 18.3.1, "Management of RANGE and LIST Partitions" and Section 13.1.7, "ALTER TABLE Syntax".

  • Row-based replication. When using row-based replication with MySQL Cluster, binary logging cannot be disabled. That is, the NDB storage engine ignores the value of sql_log_bin. (Bug #16680)

17.1.6.2. Limits and Differences of MySQL Cluster from Standard MySQL Limits

In this section, we list limits found in MySQL Cluster that either differ from limits found in, or that are not found in, standard MySQL.

Memory usage and recovery. Memory consumed when data is inserted into an NDB table is not automatically recovered when deleted, as it is with other storage engines. Instead, the following rules hold true:

17.1.6.3. Limits Relating to Transaction Handling in MySQL Cluster

A number of limitations exist in MySQL Cluster with regard to the handling of transactions. These include the following:

  • Transaction isolation level. The NDBCLUSTER storage engine supports only the READ COMMITTED transaction isolation level. (InnoDB, for example, supports READ COMMITTED, READ UNCOMMITTED, REPEATABLE READ, and SERIALIZABLE.) See Section 17.5.3.4, "MySQL Cluster Backup Troubleshooting", for information on how this can affect backing up and restoring Cluster databases.)

  • Transactions and BLOB or TEXT columns. NDBCLUSTER stores only part of a column value that uses any of MySQL's BLOB or TEXT data types in the table visible to MySQL; the remainder of the BLOB or TEXT is stored in a separate internal table that is not accessible to MySQL. This gives rise to two related issues of which you should be aware whenever executing SELECT statements on tables that contain columns of these types:

    1. For any SELECT from a MySQL Cluster table: If the SELECT includes a BLOB or TEXT column, the READ COMMITTED transaction isolation level is converted to a read with read lock. This is done to guarantee consistency.

    2. For any SELECT which uses a unique key lookup to retrieve any columns that use any of the BLOB or TEXT data types and that is executed within a transaction, a shared read lock is held on the table for the duration of the transaction-that is, until the transaction is either committed or aborted.

      This issue does not occur for queries that use index or table scans, even against NDB tables having BLOB or TEXT columns.

      For example, consider the table t defined by the following CREATE TABLE statement:

      CREATE TABLE t ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT NOT NULL, c INT NOT NULL, d TEXT, INDEX i(b), UNIQUE KEY u(c)) ENGINE = NDB,

      Either of the following queries on t causes a shared read lock, because the first query uses a primary key lookup and the second uses a unique key lookup:

      SELECT * FROM t WHERE a = 1;SELECT * FROM t WHERE c = 1;

      However, none of the four queries shown here causes a shared read lock:

      SELECT * FROM t WHERE b 1;SELECT * FROM t WHERE d = '1';SELECT * FROM t;SELECT b,c WHERE a = 1; 

      This is because, of these four queries, the first uses an index scan, the second and third use table scans, and the fourth, while using a primary key lookup, does not retrieve the value of any BLOB or TEXT columns.

      You can help minimize issues with shared read locks by avoiding queries that use unique key lookups that retrieve BLOB or TEXT columns, or, in cases where such queries are not avoidable, by committing transactions as soon as possible afterward.

  • Rollbacks. There are no partial transactions, and no partial rollbacks of transactions. A duplicate key or similar error causes the entire transaction to be rolled back.

    This behavior differs from that of other transactional storage engines such as InnoDB that may roll back individual statements.

  • Transactions and memory usage. As noted elsewhere in this chapter, MySQL Cluster does not handle large transactions well; it is better to perform a number of small transactions with a few operations each than to attempt a single large transaction containing a great many operations. Among other considerations, large transactions require very large amounts of memory. Because of this, the transactional behavior of a number of MySQL statements is effected as described in the following list:

    • TRUNCATE TABLE is not transactional when used on NDB tables. If a TRUNCATE TABLE fails to empty the table, then it must be re-run until it is successful.

    • DELETE FROM (even with no WHERE clause) is transactional. For tables containing a great many rows, you may find that performance is improved by using several DELETE FROM ... LIMIT ... statements to "chunk" the delete operation. If your objective is to empty the table, then you may wish to use TRUNCATE TABLE instead.

    • LOAD DATA statements. LOAD DATA INFILE is not transactional when used on NDB tables.

      Important

      When executing a LOAD DATA INFILE statement, the NDB engine performs commits at irregular intervals that enable better utilization of the communication network. It is not possible to know ahead of time when such commits take place.

      LOAD DATA FROM MASTER is not supported in MySQL Cluster.

    • ALTER TABLE and transactions. When copying an NDB table as part of an ALTER TABLE, the creation of the copy is nontransactional. (In any case, this operation is rolled back when the copy is deleted.)

  • Transactions and the COUNT() function. When using MySQL Cluster Replication, it is not possible to guarantee the transactional consistency of the COUNT() function on the slave. In other words, when performing on the master a series of statements (INSERT, DELETE, or both) that changes the number of rows in a table within a single transaction, executing SELECT COUNT(*) FROM table queries on the slave may yield intermediate results. This is due to the fact that SELECT COUNT(...) may perform dirty reads, and is not a bug in the NDB storage engine. (See Bug #31321 for more information.)

17.1.6.4. MySQL Cluster Error Handling

Starting, stopping, or restarting a node may give rise to temporary errors causing some transactions to fail. These include the following cases:

  • Temporary errors. When first starting a node, it is possible that you may see Error 1204 Temporary failure, distribution changed and similar temporary errors.

  • Errors due to node failure. The stopping or failure of any data node can result in a number of different node failure errors. (However, there should be no aborted transactions when performing a planned shutdown of the cluster.)

In either of these cases, any errors that are generated must be handled within the application. This should be done by retrying the transaction.

See also Section 17.1.6.2, "Limits and Differences of MySQL Cluster from Standard MySQL Limits".

17.1.6.5. Limits Associated with Database Objects in MySQL Cluster

Some database objects such as tables and indexes have different limitations when using the NDBCLUSTER storage engine:

  • Number of database objects. The maximum number of all NDB database objects in a single MySQL Cluster-including databases, tables, and indexes-is limited to 20320.

  • Attributes per table. The maximum number of attributes (that is, columns and indexes) that can belong to a given table is 512.

  • Attributes per key. The maximum number of attributes per key is 32.

  • Row size. The maximum permitted size of any one row is 14000 bytes (as of MySQL Cluster NDB 7.0). Each BLOB or TEXT column contributes 256 + 8 = 264 bytes to this total.

  • Number of rows per partition. The maximum number of rows that can be stored in a single MySQL Cluster partition varies with the number of replicas times the number of fragments. A single fragment can hold a maximum of approximately 45 million rows. Since the number of partitions is the same as the number of data nodes in the cluster (see Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions"), you can increase the number of fragments-and thus the available space-by using more data nodes.

    In MySQL Cluster NDB 7.0 and later MySQL Cluster release series, you can increase the number of data nodes in the cluster while the cluster remains in operation. See Section 17.5.13, "Adding MySQL Cluster Data Nodes Online", for more information.

    It is also possible to increase the number of partitions for NDB tables by using explicit KEY or LINEAR KEY partitioning (see Section 18.2.5, "KEY Partitioning").

17.1.6.6. Unsupported or Missing Features in MySQL Cluster

A number of features supported by other storage engines are not supported for NDB tables. Trying to use any of these features in MySQL Cluster does not cause errors in or of itself; however, errors may occur in applications that expects the features to be supported or enforced:

  • Foreign key constraints. The foreign key construct is ignored, just as it is in MyISAM tables.

  • Index prefixes. Prefixes on indexes are not supported for NDBCLUSTER tables. If a prefix is used as part of an index specification in a statement such as CREATE TABLE, ALTER TABLE, or CREATE INDEX, the prefix is ignored.

  • LOAD TABLE ... FROM MASTER. LOAD TABLE FROM MASTER is not supported.

  • Savepoints and rollbacks. Savepoints and rollbacks to savepoints are ignored as in MyISAM.

  • Durability of commits. There are no durable commits on disk. Commits are replicated, but there is no guarantee that logs are flushed to disk on commit.

  • Replication. Statement-based replication is not supported. Use --binlog-format=ROW (or --binlog-format=MIXED) when setting up cluster replication. See Section 17.6, "MySQL Cluster Replication", for more information.

Note

See Section 17.1.6.3, "Limits Relating to Transaction Handling in MySQL Cluster", for more information relating to limitations on transaction handling in NDB.

17.1.6.7. Limitations Relating to Performance in MySQL Cluster

The following performance issues are specific to or especially pronounced in MySQL Cluster:

  • Range scans. There are query performance issues due to sequential access to the NDB storage engine; it is also relatively more expensive to do many range scans than it is with either MyISAM or InnoDB.

  • Reliability of Records in range. The Records in range statistic is available but is not completely tested or officially supported. This may result in nonoptimal query plans in some cases. If necessary, you can employ USE INDEX or FORCE INDEX to alter the execution plan. See Section 13.2.9.3, "Index Hint Syntax", for more information on how to do this.

  • Unique hash indexes. Unique hash indexes created with USING HASH cannot be used for accessing a table if NULL is given as part of the key.

17.1.6.8. Issues Exclusive to MySQL Cluster

The following are limitations specific to the NDBCLUSTER storage engine:

  • Machine architecture. All machines used in the cluster must have the same architecture. That is, all machines hosting nodes must be either big-endian or little-endian, and you cannot use a mixture of both. For example, you cannot have a management node running on a PowerPC which directs a data node that is running on an x86 machine. This restriction does not apply to machines simply running mysql or other clients that may be accessing the cluster's SQL nodes.

  • Binary logging. MySQL Cluster has the following limitations or restrictions with regard to binary logging:

See also Section 17.1.6.10, "Limitations Relating to Multiple MySQL Cluster Nodes".

17.1.6.9. Limitations Relating to MySQL Cluster Disk Data Storage

Disk Data object maximums and minimums. Disk data objects are subject to the following maximums and minimums:

  • Maximum number of tablespaces: 232 (4294967296)

  • Maximum number of data files per tablespace: 216 (65536)

  • Maximum data file size: The theoretical limit is 64G; however, the practical upper limit is 32G. This is equivalent to 32768 extents of 1M each.

    Since a MySQL Cluster Disk Data table can use at most 1 tablespace, this means that the theoretical upper limit to the amount of data (in bytes) that can be stored on disk by a single NDB table is 32G * 65536 = 2251799813685248, or approximately 2 petabytes.

  • The theoretical maximum number of extents per tablespace data file is 216 (65536); however, for practical purposes, the recommended maximum number of extents per data file is 215 (32768).

    The minimum and maximum possible sizes of extents for tablespace data files are 32K and 2G, respectively. See Section 13.1.18, "CREATE TABLESPACE Syntax", for more information.

Disk Data tables and diskless mode. Use of Disk Data tables is not supported when running the cluster in diskless mode. Beginning with MySQL 5.1.12, it is prohibited altogether. (Bug #20008)

17.1.6.10. Limitations Relating to Multiple MySQL Cluster Nodes

Multiple SQL nodes. The following are issues relating to the use of multiple MySQL servers as MySQL Cluster SQL nodes, and are specific to the NDBCLUSTER storage engine:

  • No distributed table locks. A LOCK TABLES works only for the SQL node on which the lock is issued; no other SQL node in the cluster "sees" this lock. This is also true for a lock issued by any statement that locks tables as part of its operations. (See next item for an example.)

  • ALTER TABLE operations. ALTER TABLE is not fully locking when running multiple MySQL servers (SQL nodes). (As discussed in the previous item, MySQL Cluster does not support distributed table locks.)

Multiple management nodes. When using multiple management servers:

  • You must give nodes explicit IDs in connect strings because automatic allocation of node IDs does not work across multiple management servers.

  • When a management server starts, it first checks for any other management server in the same MySQL Cluster, and upon successful connection to the other management server uses its configuration data. This means that the management server --reload and --initial startup options are ignored unless the management server is the only one running. It also means that, when performing a rolling restart of a MySQL Cluster with multiple management nodes, the management server reads its own configuration file if (and only if) it is the only management server running in this MySQL Cluster. See Section 17.5.5, "Performing a Rolling Restart of a MySQL Cluster", for more information.

Multiple network addresses. Multiple network addresses per data node are not supported. Use of these is liable to cause problems: In the event of a data node failure, an SQL node waits for confirmation that the data node went down but never receives it because another route to that data node remains open. This can effectively make the cluster inoperable.

Note

It is possible to use multiple network hardware interfaces (such as Ethernet cards) for a single data node, but these must be bound to the same address. This also means that it not possible to use more than one [tcp] section per connection in the config.ini file. See Section 17.3.2.8, "MySQL Cluster TCP/IP Connections", for more information.

17.1.6.11. Previous MySQL Cluster Issues Resolved in MySQL 5.1, MySQL Cluster NDB6.x, and MySQL Cluster NDB 7.x

A number of limitations and related issues existing in earlier versions of MySQL Cluster have been resolved:

  • Variable-length column support. The NDBCLUSTER storage engine now supports variable-length column types for in-memory tables.

    Previously, for example, any Cluster table having one or more VARCHAR fields which contained only relatively small values, much more memory and disk space were required when using the NDBCLUSTER storage engine than would have been the case for the same table and data using the MyISAM engine. In other words, in the case of a VARCHAR column, such a column required the same amount of storage as a CHAR column of the same size. In MySQL 5.1, this is no longer the case for in-memory tables, where storage requirements for variable-length column types such as VARCHAR and BINARY are comparable to those for these column types when used in MyISAM tables (see Section 11.6, "Data Type Storage Requirements").

    Important

    For MySQL Cluster Disk Data tables, the fixed-width limitation continues to apply. See Section 17.5.12, "MySQL Cluster Disk Data Tables".

  • Replication with MySQL Cluster. It is now possible to use MySQL replication with Cluster databases. For details, see Section 17.6, "MySQL Cluster Replication".

    Circular Replication. Circular replication is also supported with MySQL Cluster, beginning with MySQL 5.1.18. See Section 17.6.10, "MySQL Cluster Replication: Multi-Master and Circular Replication".

  • auto_increment_increment and auto_increment_offset. The auto_increment_increment and auto_increment_offset server system variables are supported for MySQL Cluster Replication.

  • Backup and restore between architectures. It is possible to perform a Cluster backup and restore between different architectures. Previously-for example-you could not back up a cluster running on a big-endian platform and then restore from that backup to a cluster running on a little-endian system. (Bug #19255)

  • Multiple data nodes, multi-threaded data nodes. MySQL Cluster NDB 7.2 supports multiple data node processes on a single host as well as multi-threaded data node processes. See Section 17.4.3, "ndbmtd - The MySQL Cluster Data Node Daemon (Multi-Threaded)", for more information.

  • Identifiers. Formerly (in MySQL 5.0 and earlier), database names, table names and attribute names could not be as long for NDB tables as tables using other storage engines, because attribute names were truncated internally. In MySQL 5.1 and later, names of MySQL Cluster databases, tables, and table columns follow the same rules regarding length as they do for any other storage engine.

  • Length of CREATE TABLE statements. CREATE TABLE statements may be no more than 4096 characters in length. This limitation affects MySQL 5.1.6, 5.1.7, and 5.1.8 only. (See Bug #17813)

  • IGNORE and REPLACE functionality. In MySQL 5.1.7 and earlier, INSERT IGNORE, UPDATE IGNORE, and REPLACE were supported only for primary keys, but not for unique keys. It was possible to work around this issue by removing the constraint, then dropping the unique index, performing any inserts, and then adding the unique index again.

    This limitation was removed for INSERT IGNORE and REPLACE in MySQL 5.1.8. (See Bug #17431.)

  • AUTO_INCREMENT columns. In MySQL 5.1.10 and earlier versions, the maximum number of tables having AUTO_INCREMENT columns-including those belonging to hidden primary keys-was 2048.

    This limitation was lifted in MySQL 5.1.11.

  • Maximum number of cluster nodes. The total maximum number of nodes in a MySQL Cluster is 255, including all SQL nodes (MySQL Servers), API nodes (applications accessing the cluster other than MySQL servers), data nodes, and management servers. The total number of data nodes and management nodes is 63, of which up to 48 can be data nodes.

    Note

    A data node cannot have a node ID greater than 49.

  • Recovery of memory from deleted rows. Memory can be reclaimed from an NDB table for reuse with any NDB table by employing OPTIMIZE TABLE, subject to the following limitations:

    You can regulate the effects of OPTIMIZE on performance by adjusting the value of the global system variable ndb_optimization_delay, which sets the number of milliseconds to wait between batches of rows being processed by OPTIMIZE. The default value is 10 milliseconds. It is possible to set a lower value (to a minimum of 0), but not recommended. The maximum is 100000 milliseconds (that is, 100 seconds).

  • Number of tables. The maximum number of NDBCLUSTER tables in a single MySQL Cluster is included in the total maximum number of NDBCLUSTER database objects (20320). (See Section 17.1.6.5, "Limits Associated with Database Objects in MySQL Cluster".)

  • Adding and dropping of data nodes. In MySQL Cluster NDB 7.2 (MySQL Cluster NDB 7.0 and later), it is possible to add new data nodes to a running MySQL Cluster by performing a rolling restart, so that the cluster and the data stored in it remain available to applications.

    When planning to increase the number of data nodes in the cluster online, you should be aware of and take into account the following issues:

    • New data nodes can be added online to a MySQL Cluster only as part of a new node group.

    • New data nodes can be added online, but cannot be dropped online. Reducing the number of data nodes requires a system restart of the cluster.

    • As in previous MySQL Cluster releases, it is not possible to change online either the number of replicas (NoOfReplicas configuration parameter) or the number of data nodes per node group. These changes require a system restart.

    • Redistribution of existing cluster data using the new data nodes is not automatic; however, this can be accomplished using simple SQL statements in the mysql client or other MySQL client application once the nodes have been added. During this procedure, it is not possible to perform DDL operations, although DML operations can continue as normal.

      The distribution of new cluster data (that is, data stored in the cluster after the new nodes have been added) uses the new nodes without manual intervention.

    For more information, see Section 17.5.13, "Adding MySQL Cluster Data Nodes Online".

  • Distribution of MySQL users and privileges. Previously, MySQL users and privileges created on one SQL node were unique to that SQL node, due to the fact that the MySQL grant tables were restricted to using the MyISAM storage engine. Beginning with MySQL Cluster NDB 7.2.0, it is possible, following installation of the MySQL Cluster software and setup of the desired users and privileges on one SQL node, to convert the grant tables to use NDB and thus to distribute the users and privileges across all SQL nodes connected to the cluster. You can do this by loading and making use of a set of stored procedures defined in an SQL script supplied with the MySQL Cluster distribution. For more information, see Section 17.5.14, "Distributed MySQL Privileges for MySQL Cluster".

  • Number of rows per partition. Previously, a single MySQL Cluster partition could hold a maximum of 46137488 rows. This limitation was removed in MySQL Cluster NDB 7.2.9.

    If you are still using a previous MySQL Cluster release, you can work around this limitation by taking advantage of the fact that the number of partitions is the same as the number of data nodes in the cluster (see Section 17.1.2, "MySQL Cluster Nodes, Node Groups, Replicas, and Partitions"). This means that, by increasing the number of data nodes, you can increase the available space for storing data.

    MySQL Cluster NDB 7.2 also supports increasing the number of data nodes in the cluster while the cluster remains in operation. See Section 17.5.13, "Adding MySQL Cluster Data Nodes Online", for more information.

    It is also possible to increase the number of partitions for NDB tables by using explicit KEY or LINEAR KEY partitioning (see Section 18.2.5, "KEY Partitioning").

17.2. MySQL Cluster Installation

This section describes the basics for planning, installing, configuring, and running a MySQL Cluster. Whereas the examples in Section 17.3, "MySQL Cluster Configuration" provide more in-depth information on a variety of clustering options and configuration, the result of following the guidelines and procedures outlined here should be a usable MySQL Cluster which meets the minimum requirements for availability and safeguarding of data.

For information about upgrading or downgrading a MySQL Cluster between release versions, see Section 17.2.7, "Upgrading and Downgrading MySQL Cluster NDB 7.2".

This section covers hardware and software requirements; networking issues; installation of MySQL Cluster; configuration issues; starting, stopping, and restarting the cluster; loading of a sample database; and performing queries.

Assumptions. The following sections make a number of assumptions regarding the cluster's physical and network configuration. These assumptions are discussed in the next few paragraphs.

Cluster nodes and host computers. The cluster consists of four nodes, each on a separate host computer, and each with a fixed network address on a typical Ethernet network as shown here:

NodeIP Address
Management node (mgmd)192.168.0.10
SQL node (mysqld)192.168.0.20
Data node "A" (ndbd)192.168.0.30
Data node "B" (ndbd)192.168.0.40

This may be made clearer by the following diagram:

MySQL Cluster Multi-Computer Setup

Network addressing. In the interest of simplicity (and reliability), this How-To uses only numeric IP addresses. However, if DNS resolution is available on your network, it is possible to use host names in lieu of IP addresses in configuring Cluster. Alternatively, you can use the hosts file (typically /etc/hosts for Linux and other Unix-like operating systems, C:\WINDOWS\system32\drivers\etc\hosts on Windows, or your operating system's equivalent) for providing a means to do host lookup if such is available.

Potential hosts file issues. A common problem when trying to use host names for Cluster nodes arises because of the way in which some operating systems (including some Linux distributions) set up the system's own host name in the /etc/hosts during installation. Consider two machines with the host names ndb1 and ndb2, both in the cluster network domain. Red Hat Linux (including some derivatives such as CentOS and Fedora) places the following entries in these machines' /etc/hosts files:

#  ndb1 /etc/hosts:127.0.0.1   ndb1.cluster ndb1 localhost.localdomain localhost
#  ndb2 /etc/hosts:127.0.0.1   ndb2.cluster ndb2 localhost.localdomain localhost

SUSE Linux (including OpenSUSE) places these entries in the machines' /etc/hosts files:

#  ndb1 /etc/hosts:127.0.0.1   localhost127.0.0.2   ndb1.cluster ndb1
#  ndb2 /etc/hosts:127.0.0.1   localhost127.0.0.2   ndb2.cluster ndb2

In both instances, ndb1 routes ndb1.cluster to a loopback IP address, but gets a public IP address from DNS for ndb2.cluster, while ndb2 routes ndb2.cluster to a loopback address and obtains a public address for ndb1.cluster. The result is that each data node connects to the management server, but cannot tell when any other data nodes have connected, and so the data nodes appear to hang while starting.

Caution

You cannot mix localhost and other host names or IP addresses in config.ini. For these reasons, the solution in such cases (other than to use IP addresses for all config.ini HostName entries) is to remove the fully qualified host names from /etc/hosts and use these in config.ini for all cluster hosts.

Host computer type. Each host computer in our installation scenario is an Intel-based desktop PC running a supported operating system installed to disk in a standard configuration, and running no unnecessary services. The core operating system with standard TCP/IP networking capabilities should be sufficient. Also for the sake of simplicity, we also assume that the file systems on all hosts are set up identically. In the event that they are not, you should adapt these instructions accordingly.

Network hardware. Standard 100 Mbps or 1 gigabit Ethernet cards are installed on each machine, along with the proper drivers for the cards, and that all four hosts are connected through a standard-issue Ethernet networking appliance such as a switch. (All machines should use network cards with the same throughout. That is, all four machines in the cluster should have 100 Mbps cards or all four machines should have 1 Gbps cards.) MySQL Cluster works in a 100 Mbps network; however, gigabit Ethernet provides better performance.

Important

MySQL Cluster is not intended for use in a network for which throughput is less than 100 Mbps or which experiences a high degree of latency. For this reason (among others), attempting to run a MySQL Cluster over a wide area network such as the Internet is not likely to be successful, and is not supported in production.

Sample data. We use the world database which is available for download from the MySQL Web site (see http://dev.mysql.com/doc/index-other.html). We assume that each machine has sufficient memory for running the operating system, required MySQL Cluster processes, and (on the data nodes) storing the database.

For general information about installing MySQL, see Chapter 2, Installing and Upgrading MySQL. For information about installation of MySQL Cluster on Linux and other Unix-like operating systems, see Section 17.2.1, "Installing MySQL Cluster on Linux". For information about installation of MySQL Cluster on Windows operating systems, see Section 17.2.2, "Installing MySQL Cluster on Windows".

For general information about MySQL Cluster hardware, software, and networking requirements, see Section 17.1.3, "MySQL Cluster Hardware, Software, and Networking Requirements".

17.2.1. Installing MySQL Cluster on Linux

This section covers installation of MySQL Cluster on Linux and other Unix-like operating systems. While the next few sections refer to a Linux operating system, the instructions and procedures given there should be easily adaptable to other supported Unix-like platforms.

MySQL Cluster NDB 7.2 is also available for Windows operating systems; for installation and setup instructions specific to Windows, see Section 17.2.2, "Installing MySQL Cluster on Windows".

Each MySQL Cluster host computer must have the correct executable programs installed. A host running an SQL node must have installed on it a MySQL Server binary (mysqld). Management nodes require the management server daemon (ndb_mgmd); data nodes require the data node daemon (ndbd or ndbmtd). It is not necessary to install the MySQL Server binary on management node hosts and data node hosts. It is recommended that you also install the management client (ndb_mgm) on the management server host.

Installation of MySQL Cluster on Linux can be done using precompiled binaries from Oracle (downloaded as a .tar.gz archive), with RPM packages (also available from Oracle), or from source code. All three of these installation methods are described in the section that follow.

Regardless of the method used, it is still necessary following installation of the MySQL Cluster binaries to create configuration files for all cluster nodes, before you can start the cluster. See Section 17.2.3, "Initial Configuration of MySQL Cluster".

17.2.1.1. Installing a MySQL Cluster Binary Release on Linux

This section covers the steps necessary to install the correct executables for each type of Cluster node from precompiled binaries supplied by Oracle.

For setting up a cluster using precompiled binaries, the first step in the installation process for each cluster host is to download the latest MySQL Cluster NDB 7.2 binary archive (mysql-cluster-gpl-7.2.10-linux-i686-glibc23.tar.gz) from the MySQL Cluster downloads area. We assume that you have placed this file in each machine's /var/tmp directory. (If you do require a custom binary, see Section 2.10.3, "Installing MySQL from a Development Source Tree".)

Note

After completing the installation, do not yet start any of the binaries. We show you how to do so following the configuration of the nodes (see Section 17.2.3, "Initial Configuration of MySQL Cluster").

SQL nodes. On each of the machines designated to host SQL nodes, perform the following steps as the system root user:

  1. Check your /etc/passwd and /etc/group files (or use whatever tools are provided by your operating system for managing users and groups) to see whether there is already a mysql group and mysql user on the system. Some OS distributions create these as part of the operating system installation process. If they are not already present, create a new mysql user group, and then add a mysql user to this group:

    shell> groupadd mysqlshell> useradd -g mysql mysql

    The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.

  2. Change location to the directory containing the downloaded file, unpack the archive, and create a symbolic link named mysql to the mysql directory. Note that the actual file and directory names vary according to the MySQL Cluster version number.

    shell> cd /var/tmpshell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.2.10-linux2.6.tar.gzshell> ln -s /usr/local/mysql-cluster-gpl-7.2.10-linux2.6-i686 /usr/local/mysql
  3. Change location to the mysql directory and run the supplied script for creating the system databases:

    shell> cd mysqlshell> scripts/mysql_install_db --user=mysql
  4. Set the necessary permissions for the MySQL server and data directories:

    shell> chown -R root .shell> chown -R mysql datashell> chgrp -R mysql .
  5. Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:

    shell> cp support-files/mysql.server /etc/rc.d/init.d/shell> chmod +x /etc/rc.d/init.d/mysql.servershell> chkconfig --add mysql.server

    (The startup scripts directory may vary depending on your operating system and version-for example, in some Linux distributions, it is /etc/init.d.)

    Here we use Red Hat's chkconfig for creating links to the startup scripts; use whatever means is appropriate for this purpose on your platform, such as update-rc.d on Debian.

Remember that the preceding steps must be repeated on each machine where an SQL node is to reside.

Data nodes. Installation of the data nodes does not require the mysqld binary. Only the MySQL Cluster data node executable ndbd (singlethreaded) or ndbmtd (multithreaded) is required. These binaries can also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.

As system root (that is, after using sudo, su root, or your system's equivalent for temporarily assuming the system administrator account's privileges), perform the following steps to install the data node binaries on the data node hosts:

  1. Change location to the /var/tmp directory, and extract the ndbd and ndbmtd binaries from the archive into a suitable directory such as /usr/local/bin:

    shell> cd /var/tmpshell> tar -zxvf mysql-5.5.29-ndb-7.2.10-linux-i686-glibc23.tar.gzshell> cd mysql-5.5.29-ndb-7.2.10-linux-i686-glibc23shell> cp bin/ndbd /usr/local/bin/ndbdshell> cp bin/ndbmtd /usr/local/bin/ndbmtd

    (You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)

  2. Change location to the directory into which you copied the files, and then make both of them executable:

    shell> cd /usr/local/binshell> chmod +x ndb*

The preceding steps should be repeated on each data node host.

Although only one of the data node executables is required to run a MySQL Cluster data node, we have shown you how to install both ndbd and ndbmtd in the preceding instructions. We recommend that you do this when installing or upgrading MySQL Cluster, even if you plan to use only one of them, since this will save time and trouble in the event that you later decide to change from one to the other.

Note

The data directory on each machine hosting a data node is /usr/local/mysql/data. This piece of information is essential when configuring the management node. (See Section 17.2.3, "Initial Configuration of MySQL Cluster".)

Management nodes. Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required; you most likely want to install the management client (ndb_mgm) as well. Both of these binaries also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.

As system root, perform the following steps to install ndb_mgmd and ndb_mgm on the management node host:

  1. Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:

    shell> cd /var/tmpshell> tar -zxvf mysql-5.5.29-ndb-7.2.10-linux2.6-i686.tar.gzshell> cd mysql-5.5.29-ndb-7.2.10-linux2.6-i686shell> cp bin/ndb_mgm* /usr/local/bin

    (You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)

  2. Change location to the directory into which you copied the files, and then make both of them executable:

    shell> cd /usr/local/binshell> chmod +x ndb_mgm*

In Section 17.2.3, "Initial Configuration of MySQL Cluster", we create configuration files for all of the nodes in our example MySQL Cluster.

17.2.1.2. Installing MySQL Cluster from RPM

This section covers the steps necessary to install the correct executables for each type of MySQL Cluster node using RPM packages supplied by Oracle.

RPMs are available for both 32-bit and 64-bit Linux platforms. The filenames for these RPMs use the following pattern:

MySQL-Cluster-component-producttype-ndbversion.distribution.architecture.rpmcomponent:= {server | client [| other]}producttype:= {gpl | advanced}ndbversion:= major.minor.releasedistribution:= {sles10 | rhel5 | el6}architecture:= {i386 | x86_64}

The component can be server or client. (Other values are possible, but since only the server and client components are required for a working MySQL Cluster installation, we do not discuss them here.) The producttype for Community RPMs downloaded from http://dev.mysql.com/downloads/cluster/ is always gpl; advanced is used to indicate commercial releases. ndbversion represents the three-part NDB storage engine version number in 7.2.x format. The distribution can be one of sles11 (SUSE Enterprise Linux 11), rhel5 (Oracle Linux 5, Red Hat Enterprise Linux 4 and 5), or el6 (Oracle Linux 6, Red Hat Enterprise Linux 6) The architecture is i386 for 32-bit RPMs and x86_64 for 64-bit versions.

For a MySQL Cluster, one and possibly two RPMs are required:

  • The server RPM (for example, MySQL-Cluster-server-gpl-7.2.10-1.sles11.i386.rpm), which supplies the core files needed to run a MySQL Server with NDBCLUSTER storage engine support (that is, as a MySQL Cluster SQL node) as well as all MySQL Cluster executables, including the management node, data node, and ndb_mgm client binaries. This RPM is always required for installing MySQL Cluster NDB 7.2.

  • If you do not have your own client application capable of administering a MySQL server, you should also obtain and install the client RPM (for example, MySQL-Cluster-client-gpl-7.2.10-1.sles11.i386.rpm), which supplies the mysql client

The MySQL Cluster version number in the RPM file names (shown here as 7.2.10) can vary according to the version which you are actually using. It is very important that all of the Cluster RPMs to be installed have the same version number. The architecture designation should be appropriate to the machine on which the RPM is to be installed; in particular, you should keep in mind that 64-bit RPMs cannot be used with 32-bit operating system.

Data nodes. On a computer that is to host a cluster data node it is necessary to install only the server RPM. To do so, copy this RPM to the data node host, and run the following command as the system root user, replacing the name shown for the RPM as necessary to match that of the RPM downloaded from the MySQL web site:

shell> rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.sles11.i386.rpm

Although this installs all MySQL Cluster binaries, only the program ndbd or ndbmtd (both in /usr/sbin) is actually needed to run a MySQL Cluster data node.

SQL nodes. On each machine to be used for hosting a cluster SQL node, install the server RPM by executing the following command as the system root user, replacing the name shown for the RPM as necessary to match the name of the RPM downloaded from the MySQL web site:

shell> rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.sles11.i386.rpm

This installs the MySQL server binary (mysqld) with NDB storage engine support in the /usr/sbin directory, as well as all needed MySQL Server support files. It also installs the mysql.server and mysqld_safe startup scripts (in /usr/share/mysql and /usr/bin, respectively). The RPM installer should take care of general configuration issues (such as creating the mysql user and group, if needed) automatically.

To administer the SQL node (MySQL server), you should also install the client RPM, as shown here:

shell> rpm -Uhv MySQL-Cluster-client-gpl-7.2.10-1.sles11.i386.rpm

This installs the mysql client program.

Management nodes. To install the MySQL Cluster management server, it is necessary only to use the server RPM. Copy this RPM to the computer intended to host the management node, and then install it by running the following command as the system root user (replace the name shown for the RPM as necessary to match that of the server RPM downloaded from the MySQL web site):

shell> rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.sles11.i386.rpm

Although this RPM installs many other files, only the management server binary ndb_mgmd (in the /usr/sbin directory) is actually required for running a management node. The server RPM also installs ndb_mgm, the NDB management client.

See Section 2.5.1, "Installing MySQL from RPM Packages on Linux", for general information about installing MySQL using RPMs supplied by Oracle.

After installing from RPM, you still need to configure the cluster as discussed in Section 17.2.3, "Initial Configuration of MySQL Cluster".

Note

A number of RPMs used by MySQL Cluster NDB 7.1 were made obsolete and discontinued in MySQL Cluster NDB 7.2. These include the former MySQL-Cluster-clusterj, MySQL-Cluster-extra, MySQL-Cluster-management, MySQL-Cluster-storage, and MySQL Cluster-tools RPMs; all of these have been merged into the MySQL-Cluster-server RPM. When upgrading from a MySQL Cluster NDB 7.1 RPM installation to MySQL Cluster NDB 7.2.3 or an earlier MySQL Cluster NDB 7.2 release, it was necessary to remove these packages manually before installing the MySQL Cluster NDB 7.2 MySQL-Cluster-server RPM. This issue is fixed in MySQL Cluster NDB 7.2.4 and later, where the MySQL-Cluster-server package specifically obsoletes the discontinued packages (BUG #13545589).

17.2.1.3. Building MySQL Cluster from Source on Linux

This section provides information about compiling MySQL Clusteron Linux and other Unix-like platforms. Building MySQL Cluster from source is similar to building the standard MySQL Server, although it differs in a few key respects discussed here. For general information about building MySQL from source, see Section 2.10, "Installing MySQL from Source". For information about compiling MySQL Cluster on Windows platforms, see Section 17.2.2.2, "Compiling and Installing MySQL Cluster from Source on Windows".

Building MySQL Cluster requires using the MySQL Cluster sources. These are available from the MySQL Cluster downloads page at http://dev.mysql.com/downloads/cluster/. The archived source file should have a name similar to mysql-cluster-gpl-7.2.10.tar.gz. You can also obtain MySQL development sources from launchpad.net. Attempting to build MySQL Cluster from standard MySQL Server 5.5 sources is not supported.

The WITH_NDBCLUSTER_STORAGE_ENGINE option for CMake causes the binaries for the management nodes, data nodes, and other MySQL Cluster programs to be built; it also causes mysqld to be compiled with NDB storage engine support. This option is enabled by default in the MySQL Cluster NDB 7.2 sources.

Important

Beginning with MySQL Cluster NDB 7.2.9, the WITH_NDB_JAVA option is enabled by default. This means that, by default, if CMake cannot find the location of Java on your system, the configuration process fails; if you do not wish to enable Java and ClusterJ support, you must indicate this explicitly by configuring the build using -DWITH_NDB_JAVA=OFF. (Bug #12379735) Use WITH_CLASSPATH to provide the Java classpath if needed.

For more information about CMake options specific to building MySQL Cluster, see Options for Compiling MySQL Cluster.

After you have run make && make install (or your system's equivalent), the result is similar to what is obtained by unpacking a precompiled binary to the same location.

Management nodes. When building from source and running the default make install, the management server and management client binaries (ndb_mgmd and ndb_mgm) can be found in /usr/local/mysql/bin. Only ndb_mgmd is required to be present on a management node host; however, it is also a good idea to have ndb_mgm present on the same host machine. Neither of these executables requires a specific location on the host machine's file system.

Data nodes. The only executable required on a data node host is the data node binary ndbd or ndbmtd. (mysqld, for example, does not have to be present on the host machine.) By default, when building from source, this file is placed in the directory /usr/local/mysql/bin. For installing on multiple data node hosts, only ndbd or ndbmtd need be copied to the other host machine or machines. (This assumes that all data node hosts use the same architecture and operating system; otherwise you may need to compile separately for each different platform.) The data node binary need not be in any particular location on the host's file system, as long as the location is known.

When compiling MySQL Cluster from source, no special options are required for building multi-threaded data node binaries. Configuring the build with NDB storage engine support causes ndbmtd to be built automatically; make install places the ndbmtd binary in the installation bin directory along with mysqld, ndbd, and ndb_mgm.

SQL nodes. If you compile MySQL with clustering support, and perform the default installation (using make install as the system root user), mysqld is placed in /usr/local/mysql/bin. Follow the steps given in Section 2.10, "Installing MySQL from Source" to make mysqld ready for use. If you want to run multiple SQL nodes, you can use a copy of the same mysqld executable and its associated support files on several machines. The easiest way to do this is to copy the entire /usr/local/mysql directory and all directories and files contained within it to the other SQL node host or hosts, then repeat the steps from Section 2.10, "Installing MySQL from Source" on each machine. If you configure the build with a nondefault PREFIX option, you must adjust the directory accordingly.

In Section 17.2.3, "Initial Configuration of MySQL Cluster", we create configuration files for all of the nodes in our example MySQL Cluster.

17.2.2. Installing MySQL Cluster on Windows

MySQL Cluster NDB 7.2 binaries for Windows can be obtained from http://dev.mysql.com/downloads/cluster/. For information about installing MySQL Cluster on Windows from a binary release provided by Oracle, see Section 17.2.2.1, "Installing MySQL Cluster on Windows from a Binary Release".

It is also possible to compile and install MySQL Cluster from source on Windows using Microsoft Visual Studio. For more information, see Section 17.2.2.2, "Compiling and Installing MySQL Cluster from Source on Windows".

17.2.2.1. Installing MySQL Cluster on Windows from a Binary Release

This section describes a basic installation of MySQL Cluster on Windows using a binary no-install MySQL Cluster release provided by Oracle, using the same 4-node setup outlined in the beginning of this section (see Section 17.2, "MySQL Cluster Installation"), as shown in the following table:

NodeIP Address
Management (MGMD) node192.168.0.10
MySQL server (SQL) node192.168.0.20
Data (NDBD) node "A"192.168.0.30
Data (NDBD) node "B"192.168.0.40

As on other platforms, the MySQL Cluster host computer running an SQL node must have installed on it a MySQL Server binary (mysqld.exe). You should also have the MySQL client (mysql.exe) on on this host. For management nodes and data nodes, it is not necessary to install the MySQL Server binary; however, each management node requires the management server daemon (ndb_mgmd.exe); each data node requires the data node daemon (ndbd.exe or ndbmtd.exe). For this example, we refer to ndbd.exe as the data node executable, but you can install ndbmtd.exe, the multi-threaded version of this program, instead, in exactly the same way. You should also install the management client (ndb_mgm.exe) on the management server host. This section covers the steps necessary to install the correct Windows binaries for each type of MySQL Cluster node.

Note

As with other Windows programs, MySQL Cluster executables are named with the .exe file extension. However, it is not necessary to include the .exe extension when invoking these programs from the command line. Therefore, we often simply refer to these programs in this documentation as mysqld, mysql, ndb_mgmd, and so on. You should understand that, whether we refer (for example) to mysqld or mysqld.exe, either name means the same thing (the MySQL Server program).

For setting up a MySQL Cluster using Oracles's no-install binaries, the first step in the installation process is to download the latest MySQL Cluster Windows binary archive from http://dev.mysql.com/downloads/cluster/. This archive has a filename of the form mysql-cluster-gpl-noinstall-ver-winarch.zip, where ver is the NDB storage engine version (such as 7.2.1), and arch is the architecture (32 for 32-bit binaries, and 64 for 64-bit binaries). For example, the MySQL Cluster NDB 7.2.1 no-install archive for 32-bit Windows systems is named mysql-cluster-gpl-noinstall-7.2.1-win32.zip.

You can run 32-bit MySQL Cluster binaries on both 32-bit and 64-bit versions of Windows; however, 64-bit MySQL Cluster binaries can be used only on 64-bit versions of Windows. If you are using a 32-bit version of Windows on a computer that has a 64-bit CPU, then you must use the 32-bit MySQL Cluster binaries.

To minimize the number of files that need to be downloaded from the Internet or copied between machines, we start with the computer where you intend to run the SQL node.

SQL node. We assume that you have placed a copy of the no-install archive in the directory C:\Documents and Settings\username\My Documents\Downloads on the computer having the IP address 192.168.0.20, where username is the name of the current user. (You can obtain this name using ECHO %USERNAME% on the command line.) To install and run MySQL Cluster executables as Windows services, this user should be a member of the Administrators group.

Extract all the files from the archive. The Extraction Wizard integrated with Windows Explorer is adequate for this task. (If you use a different archive program, be sure that it extracts all files and directories from the archive, and that it preserves the archive's directory structure.) When you are asked for a destination directory, enter C:\, which causes the Extraction Wizard to extract the archive to the directory C:\mysql-cluster-gpl-noinstall-ver-winarch. Rename this directory to C:\mysql.

It is possible to install the MySQL Cluster binaries to directories other than C:\mysql\bin; however, if you do so, you must modify the paths shown in this procedure accordingly. In particular, if the MySQL Server (SQL node) binary is installed to a location other than C:\mysql or C:\Program Files\MySQL\MySQL Server 5.5, or if the SQL node's data directory is in a location other than C:\mysql\data or C:\Program Files\MySQL\MySQL Server 5.5\data, extra configuration options must be used on the command line or added to the my.ini or my.cnf file when starting the SQL node. For more information about configuring a MySQL Server to run in a nonstandard location, see Section 2.3.7, "Installing MySQL on Microsoft Windows Using a noinstall Zip Archive".

For a MySQL Server with MySQL Cluster support to run as part of a MySQL Cluster, it must be started with the options --ndbcluster and --ndb-connectstring. While you can specify these options on the command line, it is usually more convenient to place them in an option file. To do this, create a new text file in Notepad or another text editor. Enter the following configuration information into this file:

[mysqld]# Options for mysqld process:ndbcluster  # run NDB storage enginendb-connectstring=192.168.0.10  # location of management server

You can add other options used by this MySQL Server if desired (see Section 2.3.7.2, "Creating an Option File"), but the file must contain the options shown, at a minimum. Save this file as C:\mysql\my.ini. This completes the installation and setup for the SQL node.

Data nodes. A MySQL Cluster data node on a Windows host requires only a single executable, one of either ndbd.exe or ndbmtd.exe. For this example, we assume that you are using ndbd.exe, but the same instructions apply when using ndbmtd.exe. On each computer where you wish to run a data node (the computers having the IP addresses 192.168.0.30 and 192.168.0.40), create the directories C:\mysql, C:\mysql\bin, and C:\mysql\cluster-data; then, on the computer where you downloaded and extracted the no-install archive, locate ndbd.exe in the C:\mysql\bin directory. Copy this file to the C:\mysql\bin directory on each of the two data node hosts.

To function as part of a MySQL Cluster, each data node must be given the address or hostname of the management server. You can supply this information on the command line using the --ndb-connectstring or -c option when starting each data node process. However, it is usually preferable to put this information in an option file. To do this, create a new text file in Notepad or another text editor and enter the following text:

[mysql_cluster]# Options for data node process:ndb-connectstring=192.168.0.10  # location of management server

Save this file as C:\mysql\my.ini on the data node host. Create another text file containing the same information and save it on as C:mysql\my.ini on the other data node host, or copy the my.ini file from the first data node host to the second one, making sure to place the copy in the second data node's C:\mysql directory. Both data node hosts are now ready to be used in the MySQL Cluster, which leaves only the management node to be installed and configured.

Management node. The only executable program required on a computer used for hosting a MySQL Cluster management node is the management server program ndb_mgmd.exe. However, in order to administer the MySQL Cluster once it has been started, you should also install the MySQL Cluster management client program ndb_mgm.exe on the same machine as the management server. Locate these two programs on the machine where you downloaded and extracted the no-install archive; this should be the directory C:\mysql\bin on the SQL node host. Create the directory C:\mysql\bin on the computer having the IP address 192.168.0.10, then copy both programs to this directory.

You should now create two configuration files for use by ndb_mgmd.exe:

  1. A local configuration file to supply configuration data specific to the management node itself. Typically, this file needs only to supply the location of the MySQL Cluster global configuration file (see item 2).

    To create this file, start a new text file in Notepad or another text editor, and enter the following information:

    [mysql_cluster]# Options for management node processconfig-file=C:/mysql/bin/config.ini

    Save this file as the plaintext file C:\mysql\bin\my.ini.

  2. A global configuration file from which the management node can obtain configuration information governing the MySQL Cluster as a whole. At a minimum, this file must contain a section for each node in the MySQL Cluster, and the IP addresses or hostnames for the management node and all data nodes (HostName configuration parameter). It is also advisable to include the following additional information:

    Create a new text file using a text editor such as Notepad, and input the following information:

    [ndbd default]# Options affecting ndbd processes on all data nodes:NoOfReplicas=2  # Number of replicasDataDir=C:/mysql/bin/cluster-data   # Directory for each data node's data files # Forward slashes used in directory path, # rather than backslashes. This is correct; # see Important note in textDataMemory=80M # Memory allocated to data storageIndexMemory=18M   # Memory allocated to index storage  # For DataMemory and IndexMemory, we have used the  # default values. Since the "world" database takes up  # only about 500KB, this should be more than enough for  # this example Cluster setup.[ndb_mgmd]# Management process options:HostName=192.168.0.10   # Hostname or IP address of management nodeDataDir=C:/mysql/bin/cluster-logs   # Directory for management node log files[ndbd]# Options for data node "A": # (one [ndbd] section per data node)HostName=192.168.0.30   # Hostname or IP address[ndbd]# Options for data node "B":HostName=192.168.0.40   # Hostname or IP address[mysqld]# SQL node options:HostName=192.168.0.20   # Hostname or IP address

    Save this file as the plaintext file C:\mysql\bin\config.ini.

Important

A single backslash character (\) cannot be used when specifying directory paths in program options or configuration files used by MySQL Cluster on Windows. Instead, you must either escape each backslash character with a second backslash (\\), or replace the backslash with a forward slash character (/). For example, the following line from the [ndb_mgmd] section of a MySQL Cluster config.ini file does not work:

DataDir=C:\mysql\bin\cluster-logs

Instead, you may use either of the following:

DataDir=C:\\mysql\\bin\\cluster-logs  # Escaped backslashes
DataDir=C:/mysql/bin/cluster-logs # Forward slashes

For reasons of brevity and legibility, we recommend that you use forward slashes in directory paths used in MySQL Cluster program options and configuration files on Windows.

17.2.2.2. Compiling and Installing MySQL Cluster from Source on Windows

Oracle provides precompiled MySQL Cluster binaries for Windows which should be adequate for most users. However, if you wish, it is also possible to compile MySQL Cluster for Windows from source code. The procedure for doing this is almost identical to the procedure used to compile the standard MySQL Server binaries for Windows, and uses the same tools. However, there are two major differences:

  • To build MySQL Cluster, you must use the MySQL Cluster sources, which you can obtain from http://dev.mysql.com/downloads/cluster/.

    Attempting to build MySQL Cluster from the source code for the standard MySQL Server is likely not to be successful, and is not supported by Oracle.

  • You must configure the build using the WITH_NDBCLUSTER_STORAGE_ENGINE or WITH_NDBCLUSTER option in addition to any other build options you wish to use with CMake. (WITH_NDBCLUSTER is supported as an alias for WITH_NDBCLUSTER_STORAGE_ENGINE, and works in exactly the same way.)

Important

Beginning with MySQL Cluster NDB 7.2.9, the WITH_NDB_JAVA option is enabled by default. This means that, by default, if CMake cannot find the location of Java on your system, the configuration process fails; if you do not wish to enable Java and ClusterJ support, you must indicate this explicitly by configuring the build using -DWITH_NDB_JAVA=OFF. (Bug #12379735) Use WITH_CLASSPATH to provide the Java classpath if needed.

For more information about CMake options specific to building MySQL Cluster, see Options for Compiling MySQL Cluster.

Once the build process is complete, you can create a Zip archive containing the compiled binaries; Section 2.10.2, "Installing MySQL from a Standard Source Distribution" provides the commands needed to perform this task on Windows systems. The MySQL Cluster binaries can be found in the bin directory of the resulting archive, which is equivalent to the no-install archive, and which can be installed and configured in the same manner. For more information, see Section 17.2.2.1, "Installing MySQL Cluster on Windows from a Binary Release".

17.2.2.3. Initial Startup of MySQL Cluster on Windows

Once the MySQL Cluster executables and needed configuration files are in place, performing an initial start of the cluster is simply a matter of starting the MySQL Cluster executables for all nodes in the cluster. Each cluster node process must be started separately, and on the host computer where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes.

  1. On the management node host, issue the following command from the command line to start the management node process:

    C:\mysql\bin> ndb_mgmd2010-06-23 07:53:34 [MgmtSrvr] INFO -- NDB Cluster Management Server. mysql-5.5.29-ndb-7.2.102010-06-23 07:53:34 [MgmtSrvr] INFO -- Reading cluster configuration from 'config.ini'

    The management node process continues to print logging output to the console. This is normal, because the management node is not running as a Windows service. (If you have used MySQL Cluster on a Unix-like platform such as Linux, you may notice that the management node's default behavior in this regard on Windows is effectively the opposite of its behavior on Unix systems, where it runs by default as a Unix daemon process. This behavior is also true of MySQL Cluster data node processes running on Windows.) For this reason, do not close the window in which ndb_mgmd.exe is running; doing so kills the management node process. (See Section 17.2.2.4, "Installing MySQL Cluster Processes as Windows Services", where we show how to install and run MySQL Cluster processes as Windows services.)

    The required -f option tells the management node where to find the global configuration file (config.ini). The long form of this option is --config-file.

    Important

    A MySQL Cluster management node caches the configuration data that it reads from config.ini; once it has created a configuration cache, it ignores the config.ini file on subsequent starts unless forced to do otherwise. This means that, if the management node fails to start due to an error in this file, you must make the management node re-read config.ini after you have corrected any errors in it. You can do this by starting ndb_mgmd.exe with the --reload or --initial option on the command line. Either of these options works to refresh the configuration cache.

    It is not necessary or advisable to use either of these options in the management node's my.ini file.

    For additional information about options which can be used with ndb_mgmd, see Section 17.4.4, "ndb_mgmd - The MySQL Cluster Management Server Daemon", as well as Section 17.4.24, "Options Common to MySQL Cluster Programs - Options Common to MySQL Cluster Programs".

  2. On each of the data node hosts, run the command shown here to start the data node processes:

    C:\mysql\bin> ndbd2010-06-23 07:53:46 [ndbd] INFO -- Configuration fetched from 'localhost:1186', generation: 1

    In each case, the first line of output from the data node process should resemble what is shown in the preceding example, and is followed by additional lines of logging output. As with the management node process, this is normal, because the data node is not running as a Windows service. For this reason, do not close the console window in which the data node process is running; doing so kills ndbd.exe. (For more information, see Section 17.2.2.4, "Installing MySQL Cluster Processes as Windows Services".)

  3. Do not start the SQL node yet; it cannot connect to the cluster until the data nodes have finished starting, which may take some time. Instead, in a new console window on the management node host, start the MySQL Cluster management client ndb_mgm.exe, which should be in C:\mysql\bin on the management node host. (Do not try to re-use the console window where ndb_mgmd.exe is running by typing CTRL+C, as this kills the management node.) The resulting output should look like this:

    C:\mysql\bin> ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm>

    When the prompt ndb_mgm> appears, this indicates that the management client is ready to receive MySQL Cluster management commands. You can observe the status of the data nodes as they start by entering ALL STATUS at the management client prompt. This command causes a running report of the data nodes's startup sequence, which should look something like this:

    ndb_mgm> ALL STATUSConnected to Management Server at: localhost:1186Node 2: starting (Last completed phase 3) (mysql-5.5.29-ndb-7.2.10)Node 3: starting (Last completed phase 3) (mysql-5.5.29-ndb-7.2.10)Node 2: starting (Last completed phase 4) (mysql-5.5.29-ndb-7.2.10)Node 3: starting (Last completed phase 4) (mysql-5.5.29-ndb-7.2.10)Node 2: Started (version 7.2.10)Node 3: Started (version 7.2.10)ndb_mgm>
    Note

    Commands issued in the management client are not case-sensitive; we use uppercase as the canonical form of these commands, but you are not required to observe this convention when inputting them into the ndb_mgm client. For more information, see Section 17.5.2, "Commands in the MySQL Cluster Management Client".

    The output produced by ALL STATUS is likely to vary from what is shown here, according to the speed at which the data nodes are able to start, the release version number of the MySQL Cluster software you are using, and other factors. What is significant is that, when you see that both data nodes have started, you are ready to start the SQL node.

    You can leave ndb_mgm.exe running; it has no negative impact on the performance of the MySQL Cluster, and we use it in the next step to verify that the SQL node is connected to the cluster after you have started it.

  4. On the computer designated as the SQL node host, open a console window and navigate to the directory where you unpacked the MySQL Cluster binaries (if you are following our example, this is C:\mysql\bin).

    Start the SQL node by invoking mysqld.exe from the command line, as shown here:

    C:\mysql\bin> mysqld --console

    The --console option causes logging information to be written to the console, which can be helpful in the event of problems. (Once you are satisfied that the SQL node is running in a satisfactory manner, you can stop it and restart it out without the --console option, so that logging is performed normally.)

    In the console window where the management client (ndb_mgm.exe) is running on the management node host, enter the SHOW command, which should produce output similar to what is shown here:

    ndb_mgm> SHOWConnected to Management Server at: localhost:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @192.168.0.30  (Version: 5.5.29-ndb-7.2.10, Nodegroup: 0, Master)id=3 @192.168.0.40  (Version: 5.5.29-ndb-7.2.10, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=1 @192.168.0.10  (Version: 5.5.29-ndb-7.2.10)[mysqld(API)]   1 node(s)id=4 @192.168.0.20  (Version: 5.5.29-ndb-7.2.10)

    You can also verify that the SQL node is connected to the MySQL Cluster in the mysql client (mysql.exe) using the SHOW ENGINE NDB STATUS statement.

You should now be ready to work with database objects and data using MySQL Cluster's NDBCLUSTER storage engine. See Section 17.2.5, "MySQL Cluster Example with Tables and Data", for more information and examples.

You can also install ndb_mgmd.exe, ndbd.exe, and ndbmtd.exe as Windows services. For information on how to do this, see Section 17.2.2.4, "Installing MySQL Cluster Processes as Windows Services").

17.2.2.4. Installing MySQL Cluster Processes as Windows Services

Once you are satisfied that MySQL Cluster is running as desired, you can install the management nodes and data nodes as Windows services, so that these processes are started and stopped automatically whenever Windows is started or stopped. This also makes it possible to control these processes from the command line with the appropriate NET START or NET STOP command, or using the Windows graphical Services utility.

Installing programs as Windows services usually must be done using an account that has Administrator rights on the system.

To install the management node as a service on Windows, invoke ndb_mgmd.exe from the command line on the machine hosting the management node, using the --install option, as shown here:

C:\> C:\mysql\bin\ndb_mgmd.exe --installInstalling service 'MySQL Cluster Management Server'   as '"C:\mysql\bin\ndbd.exe" "--service=ndb_mgmd"'Service successfully installed.
Important

When installing a MySQL Cluster program as a Windows service, you should always specify the complete path; otherwise the service installation may fail with the error The system cannot find the file specified.

The --install option must be used first, ahead of any other options that might be specified for ndb_mgmd.exe. However, it is preferable to specify such options in an options file instead. If your options file is not in one of the default locations as shown in the output of ndb_mgmd.exe --help, you can specify the location using the --config-file option.

Now you should be able to start and stop the management server like this:

C:\> NET START ndb_mgmdThe MySQL Cluster Management Server service is starting.The MySQL Cluster Management Server service was started successfully.C:\> NET STOP ndb_mgmdThe MySQL Cluster Management Server service is stopping..The MySQL Cluster Management Server service was stopped successfully.

You can also start or stop the management server as a Windows service using the descriptive name, as shown here:

C:\> NET START 'MySQL Cluster Management Server'The MySQL Cluster Management Server service is starting.The MySQL Cluster Management Server service was started successfully.C:\> NET STOP  'MySQL Cluster Management Server'The MySQL Cluster Management Server service is stopping..The MySQL Cluster Management Server service was stopped successfully.

However, it is usually simpler to specify a short service name or to permit the default service name to be used when installing the service, and then reference that name when starting or stopping the service. To specify a service name other than ndb_mgmd, append it to the --install option, as shown in this example:

C:\> C:\mysql\bin\ndb_mgmd.exe --install=mgmd1Installing service 'MySQL Cluster Management Server'   as '"C:\mysql\bin\ndb_mgmd.exe" "--service=mgmd1"'Service successfully installed.

Now you should be able to start or stop the service using the name you have specified, like this:

C:\> NET START mgmd1The MySQL Cluster Management Server service is starting.The MySQL Cluster Management Server service was started successfully.C:\> NET STOP mgmd1The MySQL Cluster Management Server service is stopping..The MySQL Cluster Management Server service was stopped successfully.

To remove the management node service, invoke ndb_mgmd.exe with the --remove option, as shown here:

C:\> C:\mysql\bin\ndb_mgmd.exe --removeRemoving service 'MySQL Cluster Management Server'Service successfully removed.

If you installed the service using a service name other than the default, you can remove the service by passing this name as the value of the --remove option, like this:

C:\> C:\mysql\bin\ndb_mgmd.exe --remove=mgmd1Removing service 'mgmd1'Service successfully removed.

Installation of a MySQL Cluster data node process as a Windows service can be done in a similar fashion, using the --install option for ndbd.exe (or ndbmtd.exe), as shown here:

C:\> C:\mysql\bin\ndbd.exe --installInstalling service 'MySQL Cluster Data Node Daemon' as '"C:\mysql\bin\ndbd.exe" "--service=ndbd"'Service successfully installed.

Now you can start or stop the data node using either the default service name or the descriptive name with net start or net stop, as shown in the following example:

C:\> NET START ndbdThe MySQL Cluster Data Node Daemon service is starting.The MySQL Cluster Data Node Daemon service was started successfully.C:\> NET STOP ndbdThe MySQL Cluster Data Node Daemon service is stopping..The MySQL Cluster Data Node Daemon service was stopped successfully.C:\> NET START 'MySQL Cluster Data Node Daemon'The MySQL Cluster Data Node Daemon service is starting.The MySQL Cluster Data Node Daemon service was started successfully.C:\> NET STOP 'MySQL Cluster Data Node Daemon'The MySQL Cluster Data Node Daemon service is stopping..The MySQL Cluster Data Node Daemon service was stopped successfully.

To remove the data node service, invoke ndbd.exe with the --remove option, as shown here:

C:\> C:\mysql\bin\ndbd.exe --removeRemoving service 'MySQL Cluster Data Node Daemon'Service successfully removed.

As with ndb_mgmd.exe (and mysqld.exe), when installing ndbd.exe as a Windows service, you can also specify a name for the service as the value of --install, and then use it when starting or stopping the service, like this:

C:\> C:\mysql\bin\ndbd.exe --install=dnode1Installing service 'dnode1' as '"C:\mysql\bin\ndbd.exe" "--service=dnode1"'Service successfully installed.C:\> NET START dnode1The MySQL Cluster Data Node Daemon service is starting.The MySQL Cluster Data Node Daemon service was started successfully.C:\> NET STOP dnode1The MySQL Cluster Data Node Daemon service is stopping..The MySQL Cluster Data Node Daemon service was stopped successfully.

If you specified a service name when installing the data node service, you can use this name when removing it as well, by passing it as the value of the --remove option, as shown here:

C:\> C:\mysql\bin\ndbd.exe --remove=dnode1Removing service 'dnode1'Service successfully removed.

Installation of the SQL node as a Windows service, starting the service, stopping the service, and removing the service are done in a similar fashion, using mysqld --install, NET START, NET STOP, and mysqld --remove. For additional information, see Section 2.3.7.7, "Starting MySQL as a Windows Service".

17.2.3. Initial Configuration of MySQL Cluster

For our four-node, four-host MySQL Cluster, it is necessary to write four configuration files, one per node host.

  • Each data node or SQL node requires a my.cnf file that provides two pieces of information: a connectstring that tells the node where to find the management node, and a line telling the MySQL server on this host (the machine hosting the data node) to enable the NDBCLUSTER storage engine.

    For more information on connectstrings, see Section 17.3.2.3, "The MySQL Cluster Connectstring".

  • The management node needs a config.ini file telling it how many replicas to maintain, how much memory to allocate for data and indexes on each data node, where to find the data nodes, where to save data to disk on each data node, and where to find any SQL nodes.

Configuring the data nodes and SQL nodes. The my.cnf file needed for the data nodes is fairly simple. The configuration file should be located in the /etc directory and can be edited using any text editor. (Create the file if it does not exist.) For example:

shell> vi /etc/my.cnf
Note

We show vi being used here to create the file, but any text editor should work just as well.

For each data node and SQL node in our example setup, my.cnf should look like this:

[mysqld]# Options for mysqld process:ndbcluster  # run NDB storage engine[mysql_cluster]# Options for MySQL Cluster processes:ndb-connectstring=192.168.0.10  # location of management server

After entering the preceding information, save this file and exit the text editor. Do this for the machines hosting data node "A", data node "B", and the SQL node.

Important

Once you have started a mysqld process with the ndbcluster and ndb-connectstring parameters in the [mysqld] and [mysql_cluster] sections of the my.cnf file as shown previously, you cannot execute any CREATE TABLE or ALTER TABLE statements without having actually started the cluster. Otherwise, these statements will fail with an error. This is by design.

Configuring the management node. The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running as root):

shell> mkdir /var/lib/mysql-clustershell> cd /var/lib/mysql-clustershell> vi config.ini

For our representative setup, the config.ini file should read as follows:

[ndbd default]# Options affecting ndbd processes on all data nodes:NoOfReplicas=2 # Number of replicasDataMemory=80M # How much memory to allocate for data storageIndexMemory=18M   # How much memory to allocate for index storage  # For DataMemory and IndexMemory, we have used the  # default values. Since the "world" database takes up  # only about 500KB, this should be more than enough for  # this example Cluster setup.[tcp default]# TCP/IP options:portnumber=2202   # This the default; however, you can use any  # port that is free for all the hosts in the cluster  # Note: It is recommended that you do not specify the port  # number at all and simply allow the default value to be used  # instead[ndb_mgmd]# Management process options:hostname=192.168.0.10   # Hostname or IP address of MGM nodedatadir=/var/lib/mysql-cluster  # Directory for MGM node log files[ndbd]# Options for data node "A": # (one [ndbd] section per data node)hostname=192.168.0.30   # Hostname or IP addressdatadir=/usr/local/mysql/data   # Directory for this data node's data files[ndbd]# Options for data node "B":hostname=192.168.0.40   # Hostname or IP addressdatadir=/usr/local/mysql/data   # Directory for this data node's data files[mysqld]# SQL node options:hostname=192.168.0.20   # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
Note

The world database can be downloaded from http://dev.mysql.com/doc/, where it can be found listed under "Examples".

After all the configuration files have been created and these minimal options have been specified, you are ready to proceed with starting the cluster and verifying that all processes are running. We discuss how this is done in Section 17.2.4, "Initial Startup of MySQL Cluster".

For more detailed information about the available MySQL Cluster configuration parameters and their uses, see Section 17.3.2, "MySQL Cluster Configuration Files", and Section 17.3, "MySQL Cluster Configuration". For configuration of MySQL Cluster as relates to making backups, see Section 17.5.3.3, "Configuration for MySQL Cluster Backups".

Note

The default port for Cluster management nodes is 1186; the default port for data nodes is 2202. However, the cluster can automatically allocate ports for data nodes from those that are already free.

17.2.4. Initial Startup of MySQL Cluster

Starting the cluster is not very difficult after it has been configured. Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:

  1. On the management host, issue the following command from the system shell to start the management node process:

    shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini

    The first time that it is started, ndb_mgmd must be told where to find its configuration file, using the -f or --config-file option. (See Section 17.4.4, "ndb_mgmd - The MySQL Cluster Management Server Daemon", for details.)

    For additional options which can be used with ndb_mgmd, see Section 17.4.24, "Options Common to MySQL Cluster Programs - Options Common to MySQL Cluster Programs".

  2. On each of the data node hosts, run this command to start the ndbd process:

    shell> ndbd
  3. If you used RPM files to install MySQL on the cluster host where the SQL node is to reside, you can (and should) use the supplied startup script to start the MySQL server process on the SQL node.

If all has gone well, and the cluster has been set up correctly, the cluster should now be operational. You can test this by invoking the ndb_mgm management node client. The output should look like that shown here, although you might see some slight differences in the output depending upon the exact version of MySQL that you are using:

shell> ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> SHOWConnected to Management Server at: localhost:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @192.168.0.30  (Version: 5.5.29-ndb-7.2.10, Nodegroup: 0, Master)id=3 @192.168.0.40  (Version: 5.5.29-ndb-7.2.10, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=1 @192.168.0.10  (Version: 5.5.29-ndb-7.2.10)[mysqld(API)]   1 node(s)id=4 @192.168.0.20  (Version: 5.5.29-ndb-7.2.10)

The SQL node is referenced here as [mysqld(API)], which reflects the fact that the mysqld process is acting as a MySQL Cluster API node.

Note

The IP address shown for a given MySQL Cluster SQL or other API node in the output of SHOW is the address used by the SQL or API node to connect to the cluster data nodes, and not to any management node.

You should now be ready to work with databases, tables, and data in MySQL Cluster. See Section 17.2.5, "MySQL Cluster Example with Tables and Data", for a brief discussion.

17.2.5. MySQL Cluster Example with Tables and Data

Note

The information in this section applies to MySQL Cluster running on both Unix and Windows platforms.

Working with database tables and data in MySQL Cluster is not much different from doing so in standard MySQL. There are two key points to keep in mind:

  • For a table to be replicated in the cluster, it must use the NDBCLUSTER storage engine. To specify this, use the ENGINE=NDBCLUSTER or ENGINE=NDB option when creating the table:

    CREATE TABLE tbl_name (col_name column_definitions) ENGINE=NDBCLUSTER;

    Alternatively, for an existing table that uses a different storage engine, use ALTER TABLE to change the table to use NDBCLUSTER:

    ALTER TABLE tbl_name ENGINE=NDBCLUSTER;
  • Every NDBCLUSTER table has a primary key. If no primary key is defined by the user when a table is created, the NDBCLUSTER storage engine automatically generates a hidden one. Such a key takes up space just as does any other table index. (It is not uncommon to encounter problems due to insufficient memory for accommodating these automatically created indexes.)

If you are importing tables from an existing database using the output of mysqldump, you can open the SQL script in a text editor and add the ENGINE option to any table creation statements, or replace any existing ENGINE options. Suppose that you have the world sample database on another MySQL server that does not support MySQL Cluster, and you want to export the City table:

shell> mysqldump --add-drop-table world City > city_table.sql

The resulting city_table.sql file will contain this table creation statement (and the INSERT statements necessary to import the table data):

DROP TABLE IF EXISTS `City`;CREATE TABLE `City` (  `ID` int(11) NOT NULL auto_increment,  `Name` char(35) NOT NULL default '',  `CountryCode` char(3) NOT NULL default '',  `District` char(20) NOT NULL default '',  `Population` int(11) NOT NULL default '0',  PRIMARY KEY  (`ID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;INSERT INTO `City` VALUES (1,'Kabul','AFG','Kabol',1780000);INSERT INTO `City` VALUES (2,'Qandahar','AFG','Qandahar',237500);INSERT INTO `City` VALUES (3,'Herat','AFG','Herat',186800);(remaining INSERT statements omitted)

You need to make sure that MySQL uses the NDBCLUSTER storage engine for this table. There are two ways that this can be accomplished. One of these is to modify the table definition before importing it into the Cluster database. Using the City table as an example, modify the ENGINE option of the definition as follows:

DROP TABLE IF EXISTS `City`;CREATE TABLE `City` (  `ID` int(11) NOT NULL auto_increment,  `Name` char(35) NOT NULL default '',  `CountryCode` char(3) NOT NULL default '',  `District` char(20) NOT NULL default '',  `Population` int(11) NOT NULL default '0',  PRIMARY KEY  (`ID`)) ENGINE=NDBCLUSTER DEFAULT CHARSET=latin1;INSERT INTO `City` VALUES (1,'Kabul','AFG','Kabol',1780000);INSERT INTO `City` VALUES (2,'Qandahar','AFG','Qandahar',237500);INSERT INTO `City` VALUES (3,'Herat','AFG','Herat',186800);(remaining INSERT statements omitted)

This must be done for the definition of each table that is to be part of the clustered database. The easiest way to accomplish this is to do a search-and-replace on the file that contains the definitions and replace all instances of TYPE=engine_name or ENGINE=engine_name with ENGINE=NDBCLUSTER. If you do not want to modify the file, you can use the unmodified file to create the tables, and then use ALTER TABLE to change their storage engine. The particulars are given later in this section.

Assuming that you have already created a database named world on the SQL node of the cluster, you can then use the mysql command-line client to read city_table.sql, and create and populate the corresponding table in the usual manner:

shell> mysql world < city_table.sql

It is very important to keep in mind that the preceding command must be executed on the host where the SQL node is running (in this case, on the machine with the IP address 192.168.0.20).

To create a copy of the entire world database on the SQL node, use mysqldump on the noncluster server to export the database to a file named world.sql; for example, in the /tmp directory. Then modify the table definitions as just described and import the file into the SQL node of the cluster like this:

shell> mysql world < /tmp/world.sql

If you save the file to a different location, adjust the preceding instructions accordingly.

Running SELECT queries on the SQL node is no different from running them on any other instance of a MySQL server. To run queries from the command line, you first need to log in to the MySQL Monitor in the usual way (specify the root password at the Enter password: prompt):

shell> mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1 to server version: 5.5.29-ndb-7.2.10Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql>

We simply use the MySQL server's root account and assume that you have followed the standard security precautions for installing a MySQL server, including setting a strong root password. For more information, see Section 2.11.2, "Securing the Initial MySQL Accounts".

It is worth taking into account that Cluster nodes do not make use of the MySQL privilege system when accessing one another. Setting or changing MySQL user accounts (including the root account) effects only applications that access the SQL node, not interaction between nodes. See Section 17.5.11.2, "MySQL Cluster and MySQL Privileges", for more information.

If you did not modify the ENGINE clauses in the table definitions prior to importing the SQL script, you should run the following statements at this point:

mysql> USE world;mysql> ALTER TABLE City ENGINE=NDBCLUSTER;mysql> ALTER TABLE Country ENGINE=NDBCLUSTER;mysql> ALTER TABLE CountryLanguage ENGINE=NDBCLUSTER;

Selecting a database and running a SELECT query against a table in that database is also accomplished in the usual manner, as is exiting the MySQL Monitor:

mysql> USE world;mysql> SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5;+-----------+------------+| Name  | Population |+-----------+------------+| Bombay |   10500000 || Seoul | 9981619 || S�o Paulo | 9968485 || Shanghai  | 9696300 || Jakarta   | 9604900 |+-----------+------------+5 rows in set (0.34 sec)mysql> \qByeshell>

Applications that use MySQL can employ standard APIs to access NDB tables. It is important to remember that your application must access the SQL node, and not the management or data nodes. This brief example shows how we might execute the SELECT statement just shown by using the PHP 5.X mysqli extension running on a Web server elsewhere on the network:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"><html><head>  <meta http-equiv="Content-Type"   content="text/html; charset=iso-8859-1">  <title>SIMPLE mysqli SELECT</title></head><body><?php  # connect to SQL node:  $link = new mysqli('192.168.0.20', 'root', 'root_password', 'world');  # parameters for mysqli constructor are:  #   host, user, password, database  if( mysqli_connect_errno() ) die("Connect failed: " . mysqli_connect_error());  $query = "SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5";  # if no errors...  if( $result = $link->query($query) )  {?><table border="1" width="40%" cellpadding="4" cellspacing ="1">  <tbody>  <tr> <th width="10%">City</th> <th>Population</th>  </tr><? # then display the results... while($row = $result->fetch_object())  printf("<tr>\n  <td align=\"center\">%s</td><td>%d</td>\n</tr>\n",  $row->Name, $row->Population);?>  </tbody</table><?  # ...and verify the number of rows that were retrieved printf("<p>Affected rows: %d</p>\n", $link->affected_rows);  }  else # otherwise, tell us what went wrong echo mysqli_error();  # free the result set and the mysqli connection object  $result->close();  $link->close();?></body></html>

We assume that the process running on the Web server can reach the IP address of the SQL node.

In a similar fashion, you can use the MySQL C API, Perl-DBI, Python-mysql, or MySQL Connectors to perform the tasks of data definition and manipulation just as you would normally with MySQL.

17.2.6. Safe Shutdown and Restart of MySQL Cluster

To shut down the cluster, enter the following command in a shell on the machine hosting the management node:

shell> ndb_mgm -e shutdown

The -e option here is used to pass a command to the ndb_mgm client from the shell. (See Section 17.4.24, "Options Common to MySQL Cluster Programs - Options Common to MySQL Cluster Programs", for more information about this option.) The command causes the ndb_mgm, ndb_mgmd, and any ndbd or ndbmtd processes to terminate gracefully. Any SQL nodes can be terminated using mysqladmin shutdown and other means. On Windows platforms, assuming that you have installed the SQL node as a Windows service, you can use NET STOP MYSQL.

To restart the cluster on Unix platforms, run these commands:

  • On the management host (192.168.0.10 in our example setup):

    shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini
  • On each of the data node hosts (192.168.0.30 and 192.168.0.40):

    shell> ndbd
  • Use the ndb_mgm client to verify that both data nodes have started successfully.

  • On the SQL host (192.168.0.20):

    shell> mysqld_safe &

On Windows platforms, assuming that you have installed all MySQL Cluster processes as Windows services using the default service names (see Section 17.2.2.4, "Installing MySQL Cluster Processes as Windows Services"), you can restart the cluster as follows:

  • On the management host (192.168.0.10 in our example setup), execute the following command:

    C:\> NET START ndb_mgmd
  • On each of the data node hosts (192.168.0.30 and 192.168.0.40), execute the following command:

    C:\> NET START ndbd
  • On the management node host, use the ndb_mgm client to verify that the management node and both data nodes have started successfully (see Section 17.2.2.3, "Initial Startup of MySQL Cluster on Windows").

  • On the SQL node host (192.168.0.20), execute the following command:

    C:\> NET START mysql

In a production setting, it is usually not desirable to shut down the cluster completely. In many cases, even when making configuration changes, or performing upgrades to the cluster hardware or software (or both), which require shutting down individual host machines, it is possible to do so without shutting down the cluster as a whole by performing a rolling restart of the cluster. For more information about doing this, see Section 17.5.5, "Performing a Rolling Restart of a MySQL Cluster".

17.2.7. Upgrading and Downgrading MySQL Cluster NDB 7.2

This section provides information about MySQL Cluster software and table file compatibility between different MySQL Cluster NDB 7.2 releases with regard to performing upgrades and downgrades as well as compatibility matrices and notes. You are expected already to be familiar with installing and configuring a MySQL Cluster prior to attempting an upgrade or downgrade. See Section 17.3, "MySQL Cluster Configuration".

Important

Only compatibility between MySQL versions with regard to NDBCLUSTER is taken into account in this section, and there are likely other issues to be considered. As with any other MySQL software upgrade or downgrade, you are strongly encouraged to review the relevant portions of the MySQL Manual for the MySQL versions from which and to which you intend to migrate, before attempting an upgrade or downgrade of the MySQL Cluster software. This is especially true when planning a migration from MySQL Cluster NDB 7.1 (or earlier) to MySQL Cluster NDB 7.2, since the version of the underlying MySQL Server also changes from MySQL 5.1 to MySQL 5.5. See Section 2.12.1, "Upgrading MySQL".

Versions supported. The following versions of MySQL Cluster are supported for upgrades to MySQL Cluster NDB 7.2 (7.2.4 and later):

  • MySQL Cluster NDB 7.1 GA releases (7.1.3 and later)

  • MySQL Cluster NDB 7.0 GA releases (7.0.5 and later)

  • MySQL Cluster NDB 6.3 GA releases (6.3.8 and later) that can be upgraded to MySQL Cluster NDB 7.1

For information about upgrades and downgrades in previous MySQL Cluster release series, see Upgrade and Downgrade Compatibility: MySQL Cluster NDB 6.x, and Upgrade and downgrade compatibility: MySQL Cluster NDB 7.x.

NDB API, ClusterJ, and other applications used with recent releases of MySQL Cluster NDB 6.3 and later should continue to work with MySQL Cluster NDB 7.2.4 and later without rewriting or recompiling.

In MySQL Cluster NDB 7.2, the default values for a number of node configuration parameters have changed. See Improved default values for data node configuration parameters, for a listing of these.

In MySQL Cluster NDB 7.2.7 and later, the size of the hash map is 3840 LDM threads, an increase from 240 in previous versions. When upgrading a MySQL Cluster from MySQL Cluster NDB 7.2.6 and earlier to MySQL Cluster NDB 7.2.9 or later, you can modify existing tables online to take advantage of the new size: following the upgrade, increase the number of fragments by (for example) adding new data nodes to the cluster, and then execute ALTER ONLINE TABLE ... REORGANIZE PARTITION on any tables that were created in the older version. Following this, these tables can use the larger hash map size.

Copyright © 1997, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
(Sebelumnya) 16. Replication17.3. MySQL Cluster Configuration (Berikutnya)