MySQLForge :: View Snippet :: MySQL Cluster in 5 Minutes
So I couldn’t read that in the little textbox over there, so here it is copy/pasted into “Teh Blog”
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.
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.
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.
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.
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.
I created a directory /usr/local/mysql/cluster and put a cluster.cnf file in it. Here‘s the content.
# Cluster Example Configuration
# 2 Data Nodes
# 1 Management Node
# 1 MySQLd Node
# Management Node
# Data Nodes, Defaults
# Data Node #1
# Data Node #2
# MySQLd Node
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.
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.
Now, we start the management server.
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.
Run the SHOW command here now once in a while to get a status report.
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.
# ndbd –initial
# ndbd –initial
Check the SHOW output again and see how the data nodes connected.
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.
mysql> CREATE TABLE myclustertable (a INT, b CHAR(10)) ENGINE=ndbcluster;
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.