MySQL Cluster Quick Start Script
Many Windows users first looking to experiment with MySQL Cluster may find the process of getting everything up and running daunting. Fortunately, there’s MySQL Cluster Manager (MCM) which can help jump-start that process – and that’s all many people will need.
In my work, I frequently have to install specific version of MySQL Server or Cluster to validate behavior of a handful of commands, and MCM is a bit overkill. I have a couple of tricks that I use to quickly set up MySQL Cluster on Windows environments:
- I always use the .ZIP packages
- I have a set cluster data directory (in my case, D:\cluster-data)
- I have a standard Cluster configuration file (config.ini) that I use, with two data nodes, one management node, and two SQL nodes
- I have a script I use to do some setup and start the necessary processes, after first making sure no other Cluster is running and there are no port conflicts for MySQL SQL nodes
The Cluster configuration file is very sparse:
[ndbd default] NoOfReplicas=2 DataDir=D:\cluster-data [NDB_MGMD] HostName=127.0.0.1 NodeId=1 DataDir= D:\cluster-data # Data Nodes # One entry for each node [NDBD] HostName=127.0.0.1 NodeId=2 [NDBD] HostName=127.0.0.1 NodeId=3 # SQL Nodes # One entry for each node [MYSQLD] HostName=127.0.0.1 [MYSQLD]
If you use this configuration file, make sure that you also create the DataDir you specify – the Cluster management node will not start if it does not exist.
The batch file I use is similarly simple, but it saves me plenty of time when I have to quickly deploy a specific version for a quick 5-minute test:
REM stop MySQL SQL nodes running on ports 3307 or 3308, if any exist REM (ignore errors if mysqld isn't available on the port) bin\mysqladmin -uroot -P3307 shutdown bin\mysqladmin -uroot -P3308 shutdown REM stop MySQL data and management nodes, if running (connection failure errors can be ignored) bin\ndb_mgm -e "shutdown" REM start the MySQL Cluster management node start bin\ndb_mgmd --configdir=%CD% -f config.ini REM start the MySQL Cluster data nodes, passing --initial if the batch file received that argument start bin\ndbd %1 start bin\ndbd %1 REM created a copy of the MySQL SQL node data directory, if it doesn't already exist IF NOT EXIST %CD%\data2 XCOPY %CD%\data %CD%\data2 /i /S REM start the MySQL SQL nodes on ports 3307 and 3308 start bin\mysqld --no-defaults --basedir=%CD% --datadir=%CD%\data --port=3307 --ndbcluster --ndb-connectstring=localhost:1186 --console start bin\mysqld --no-defaults --basedir=%CD% --datadir=%CD%\data2 --port=3308 --ndbcluster --ndb-connectstring=localhost:1186 --console
The script expects to be run from within the directory created when unpacking the .ZIP file. It leverages the default (blank) password for the root account in Windows .ZIP distributions to shutdown the SQL nodes, and uses port 3307 and 3308 to avoid causing problems with any existing MySQL server that may be running on port 3306 (which is my personal, persistent installation).
Hopefully this will help people looking to do a quick deployment of MySQL Cluster on Windows.