MySQL Sandbox

Hoje vamos falar sobre uma excelente ferramenta que todo DBA MySQL precisa ter em mãos, estou falando do MySQL Sandbox.

MySQL Sandbox é desenvolvido por Giuseppe Maxia (The Data Charmer), esta ferramenta auxilia na instalação de servidores para testes. Se você precisa testar algum bug, algum caso especifico relacionado a replicação(suporta master/slave e master/master) esta é a ferramenta que tens que conhecer.

INSTALAÇÃO:

Vá até http://mysqlsandbox.net/ e baixe a versao mais atual (Pode ser via launchpad):

yum install perl perl-ExtUtils-MakeMaker perl-Test-Simple
wget https://launchpad.net/mysql-sandbox/mysql-sandbox-3/mysql-sandbox-3/+download/MySQL-Sandbox-3.0.44.tar.gz
tar -zxvf MySQL-Sandbox-3.0.44.tar.gz
cd MySQL-Sandbox-3.0.44
perl Makefile.PL
make
make test
make install

CRIANDO UMA INSTÂNCIA:

Para criar uma única instância, tudo o que precisamos é o pacote (tar.gz .rpm .deb) da versão do MySQL que desejamos instalar e o comando make_sandbox:

[root@localhost ~]# make_sandbox mysql-5.6.17-linux-glibc2.5-i686.tar.gz 
unpacking /root/mysql-5.6.17-linux-glibc2.5-i686.tar.gz
Executing low_level_make_sandbox --basedir=/root/5.6.17 \
	--sandbox_directory=msb_5_6_17 \
	--install_version=5.6 \
	--sandbox_port=5617 \
	--no_ver_after_name \
	--my_clause=log-error=msandbox.err
    The MySQL Sandbox,  version 3.0.44
    (C) 2006-2013 Giuseppe Maxia
installing with the following parameters:
upper_directory                = /root/sandboxes
sandbox_directory              = msb_5_6_17
sandbox_port                   = 5617
check_port                     = 
no_check_port                  = 
datadir_from                   = script
install_version                = 5.6
basedir                        = /root/5.6.17
tmpdir                         = 
my_file                        = 
operating_system_user          = root
db_user                        = msandbox
remote_access                  = 127.%
bind_address                   = 127.0.0.1
ro_user                        = msandbox_ro
rw_user                        = msandbox_rw
repl_user                      = rsandbox
db_password                    = msandbox
repl_password                  = rsandbox
my_clause                      = log-error=msandbox.err
master                         = 
slaveof                        = 
high_performance               = 
prompt_prefix                  = mysql
prompt_body                    =  [\h] {\u} (\d) > 
force                          = 
no_ver_after_name              = 1
verbose                        = 
load_grants                    = 1
no_load_grants                 = 
no_run                         = 
no_show                        = 
do you agree? ([Y],n) 
loading grants
.. sandbox server started
Your sandbox server was installed in $HOME/sandboxes/msb_5_6_17

Para usarmos esta instância, podemos chamar o script use que se encontra dentro da pasta que o MySQL Sandbox acabou de criar.

[root@localhost ~]# $HOME/sandboxes/msb_5_6_17/use
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql [localhost] {msandbox} ((none)) > 

Podemos gerenciar esta instância usando os scripts start / stop / restart / status, que também se encontram dentro da pasta criada.

CRIANDO REPLICAÇÃO MASTER SLAVE:

Para criar um conjunto de instâncias configuradas como master / slave (padrão: 1 master e 2 slaves, mas podemos alterar este comportamento passando o parâmetro --how_many_nodes ) vamos utilizar o comando make_replication_sandbox:

[root@localhost ~]# make_replication_sandbox mysql-5.6.17-linux-glibc2.5-i686.tar.gz 
installing and starting master
installing slave 1
installing slave 2
starting slave 1
.... sandbox server started
starting slave 2
.. sandbox server started
initializing slave 1
initializing slave 2
replication directory installed in $HOME/sandboxes/rsandbox_mysql-5_6_17

Para usar as instâncias criadas, podemos utilizar o script use que está localizado dentro das pastas nodeN (onde N é o numero da instância) e master:

[root@localhost ~]# #MASTER
[root@localhost ~]# /root/sandboxes/rsandbox_mysql-5_6_17/master/use 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

master [localhost] {msandbox} ((none)) > ^DBye
[root@localhost ~]# #SLAVE 1
[root@localhost ~]# /root/sandboxes/rsandbox_mysql-5_6_17/node1/use 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

slave1 [localhost] {msandbox} ((none)) > ^DBye
[root@localhost ~]# #SLAVE 2
[root@localhost ~]# /root/sandboxes/rsandbox_mysql-5_6_17/node2/use 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

slave2 [localhost] {msandbox} ((none)) > 

Para instâncias configuradas como replicação, podemos gerenciar cada uma delas também chamando o script start / stop / restart / status que está dentro das pastas master/nodeN ou podemos chamar os scripts terminados com _all (start_all / stop_all / restart_all / status_all) que se encontram na pasta raiz da sandbox criada.

CRIANDO REPLICAÇÃO MULTI MASTER :

Para criarmos instâncias configuradas como multi-master’s, vamos utilizar o comando make_replication_sandbox com a opção --master_master:

[root@localhost ~]# make_replication_sandbox --master_master mysql-5.6.17-linux-glibc2.5-i686.tar.gz
installing node 1
installing node 2
# server: 1: 
# server: 2: 
# server: 1: 
# server: 2: 
Circular replication activated
group directory installed in $HOME/sandboxes/rcsandbox_mysql-5_6_17

É isso aí pessoal, podemos achar mais informações usando o parâmetro –help nos comandos make_multiple_custom_sandbox make_multiple_sandbox make_replication_sandbox make_sandbox make_sandbox_from_installed and make_sandbox_from_source.

Gostou ? Ajude e Compartilhe!
Esta entrada foi publicada em instalação, MySQL, replicacao. Adicione o link permanente aos seus favoritos.
  • Lalit

    Thank you for the post, mysql sandbox save my time. Using this tool it’s so simple to setup and manage multiple mysql instances on the same machine.For me it’s helpful to test different replication topologies,cluster nodes and multi-version mysql testing.

  • Joseph Norris

    Hello to all
    I have been attempting to get just a small replication testing environment set up and I am running into problems. I have mysql-5.5.51-linux2.6-x86_64.tar.gz but when I run make_replication_sandbox mysql-5.5.51-linux2.6-x86_64.tar.gz – it runs and runs builds directories under $SANDBOX_HOME then dies:
    installing and starting master
    can’t start server
    error installing the master

    (512 )

    I cannot figure this out – I have used sandbox before and have not had this issue. SBDEBUG does not shed a whole of light on the issue. Any help would be most appreciated.

    • marceloaltmann

      Hi Joseph.
      Sorry about the delay. Have a look on your master datadir, there is a file called msandbox.err . This file will tell you why your sandbox isn’t starting.

      Please comment here if you have any other questions.