MySQL Cluster in 5 Minutes

Developed In: None/Text — Contributed by: Kai Voigt

This article shows the simplest setup of a MySQL cluster. No whistles and bells, just to get started.
Kai Voigt
None/Text
  1. You have heard about MySQL Cluster, but you were always afraid to get into it because „Cluster“ seems to be a magic and complicated topic? Then this article is for you. In a couple of minutes, you can run your own Cluster.
  2.  
  3. Sometimes, I need to demonstrate how MySQL cluster works. I usually set up a single machine cluster which of course won‘t make sense in production scenarios, but for an introduction into MySQL cluster it‘s fine. And it‘s very easy to deploy the system on multiple machines later.
  4.  
  5. This article will show you how you can set up your own Cluster. All you need is a UNIX machine and the mysql-max package (version 4.1 or 5.0) which is downloadable from the MySQL website.
  6.  
  7. Run „SHOW ENGINES“ to see that the cluster storage engine is included in your installation. If it says „DISABLED“ or „YES“ in the row for „ndbcluster“, you‘re fine and you can continue. Otherwise, get the mysql-max package. Again, it‘s only available on UNIX machines, Windows is not supported for Cluster yet.
  8.  
  9. Believe me, the most complicated part lies behind us already. Next, we are going to create a configuration file for our little cluster. It will consist of two data nodes, one management node and one mysqld node.
  10.  
  11. I created a directory /usr/local/mysql/cluster and put a cluster.cnf file in it. Here‘s the content.
  12.  
  13. # Cluster Example Configuration
  14. # 2 Data Nodes
  15. # 1 Management Node
  16. # 1 MySQLd Node
  17.  
  18. # Management Node
  19. [ndb_mgmd]
  20. Id=1
  21. Hostname=127.0.0.1
  22. DataDir=/usr/local/mysql/cluster/
  23.  
  24. # Data Nodes, Defaults
  25. [ndbd default]
  26. NoOfReplicas=2
  27. DataMemory=30M
  28. IndexMemory=10M
  29. DataDir=/usr/local/mysql/cluster/
  30.  
  31. # Data Node #1
  32. [ndbd]
  33. Id=2
  34. Hostname=127.0.0.1
  35.  
  36. # Data Node #2
  37. [ndbd]
  38. Id=3
  39. Hostname=127.0.0.1
  40.  
  41. # MySQLd Node
  42. [mysqld]
  43. Id=4
  44. Hostname=127.0.0.1
  45.  
  46. See, it‘s not complicated yet. All nodes reside on the local host and only a few parameters are set. Next, we also need to add some lines into the usual my.cnf file.
  47.  
  48. [mysql_cluster]
  49. ndb_connectstring=127.0.0.1
  50.  
  51. [mysqld]
  52. ndbcluster
  53.  
  54. [ndb_mgmd]
  55. config-file=/usr/local/mysql/cluster/cluster.cnf
  56.  
  57. Merge these lines into your existing my.cnf, they will make your mysqld enable the cluster storage engine, tell the management node where to find the configuration file and let all other nodes know where to find the management node.
  58.  
  59. Now, we start the management server.
  60.  
  61. # ndb_mgmd
  62.  
  63. Easy, huh? The management server is now running and waits for other nodes to connect. Open a new terminal window and run the management client to see what‘s going on.
  64.  
  65. # ndb_mgm
  66.  
  67. Run the SHOW command here now once in a while to get a status report.
  68.  
  69. Next, we go back to our original terminal window and start the data nodes. Since we set up the cluster the very first time, we must use the --initial option. If you later start a data node, you can omit this option. Keep in mind that we configured two data nodes, so we have to execute the ndbd program twice.
  70.  
  71. # ndbd --initial
  72. # ndbd --initial
  73.  
  74. Check the SHOW output again and see how the data nodes connected.
  75.  
  76. Now restart your mysqld server and check the SHOW output again. All nodes should be connected now and you can create your first cluster table.
  77.  
  78. mysql> CREATE TABLE myclustertable (a INT, b CHAR(10)) ENGINE=ndbcluster;
  79.  
  80. Congratulations, you‘re done. Did it hurt? I think not. Now go and play with the cluster. Tear down one data node, restart it, grow the cluster with more nodes and machines, explore the other commands of the management clients and then read all the details in the online documentation.

Current Tags

You must be logged in to tag this tool

AMSER is a portal of educational resources and services built specifically for use by those in Community and Technical Colleges but free for anyone to use. Online accredited High School AND Homeschool Online

HTML will be purified, but we allow for a number of HTML tags so that you have the flexibility to decorate your comment text to some extent. The comments allow the following HTML tags: Online high school AND Adison High School AND GED

Votes

  • Rated 5.00 out of 5
Rated 5.00 out of 5 with 1 votes cast.
You must be logged in to vote.

Watches

6 members are watching this tool
You must be logged in to track this tool.

Provide Feedback

Please note:
HTML will be purified, but we allow for a number of HTML tags so that you have the flexibility to decorate your comment text to some extent. The comments allow the following HTML tags:

strong, b, em, blockquote, a, code, pre

To put code into your comment, simply encapsulate your code with
[code language="XXX"][/code], where XXX is any common language, for instance "PHP", "SQL", "C", etc.



You must be logged in to comment