content_image/809850.jpg
You should now be ready to work with databases, tables, and data in NDB Cluster. See Section 23.2.5, “NDB Cluster Example with Tables and Data” , for a brief discussion. 

## 23.2.5 NDB Cluster Example with Tables and Data 

<img src='content_image/809850.jpg'>

## Note 

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

Working with database tables and data in NDB 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 NDB 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 contains 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‘ ( 

