Using MySQL Sandbox to test replication behavior
It is easy to set up a replication topology with MySQL Sandbox, and I use it for lots of testing scenarios. For example I used MySQL Sandbox to run the tests for yeterday’s post about the way UUIDs are replicated in row-based replication (RBR) versus statement-based replication (SBR).
Here’s how easy it is to set up a replicated sandbox for testing:
Installing MySQL Sandbox
If you’ve never installed MySQL Sandbox before, you can do so by running a single command as root:
sudo su -
cpan MySQL::Sandbox
Download the MySQL binary
Pick the appropriate binary based on your OS and the version of MySQL you want to use. In my case I’m on Mac OS X and I want to test MySQL 5.6 so I went to dev.mysql.com and downloaded the following compressed TAR archive:
mysql-5.6.22-osx10.8-x86_64.tar.gz
Create the sandbox
This is another one-liner:
make_replication_sandbox ~/Downloads/mysql-5.6.22-osx10.8-x86_64.tar.gz
Use the sandbox
MySQL Sandbox created 3 servers for me: a master and two replicas. Everything is installed under this directory:
$HOME/sandboxes/rsandbox_mysql-5_6_22
Here are the relevant my.cnf files:
master/my.sandbox.cnf
node1/my.sandbox.cnf
node2/my.sandbox.cnf
Here are some handy scripts to start and stop all 3 servers:
./start_all
./stop_all
./restart_all
And here are the handy scripts to connect to each server with the MySQL CLI:
./m
./s1
./s2
It’s easy to get confused about which server you are connected to when you are running multiple servers, so MySQL Sandbox overrides the default mysql prompt with a more information prompt. For example here’s the prompt for my master server:
master [localhost] {msandbox} ((none)) >
Happy testing!