MySQL Sandbox是一个非常简单快捷部署隔离的MySQL服务的一个工具。

可以在同一台机器上,快速的部署一个到多个相互隔离互不影响的mysqld服务。比如,开发人员要测试程序系统的不需要在mysql的安装上纠缠过多。对新版本的一些特性感兴趣,尽可能快速结束安装部署。

最短时间部署数据应用架构如Replication Cluster进行性能测试。

准备mysql_sandbox.下载地址:http://http://mysqlsandbox.net/

mysql源码安装包

步骤

1安装mysql_sandbox

cpan MySQL::Sandbox

解压

perl Makefile.pl

make

make install

设置环境变量

[root@localhost ~]# echo 'export SANDBOX_AS_ROOT=1' >> /root/.bash_profile
[root@localhost ~]# source /root/.bash_profile
建立一个存放mysql源程序的仓库,并设置环境变量。
mkdir /home/modify/mysql
#这行指令应该要添加到/home/modify/.bashrc文件中
export SANDBOX_BINARY=/home/modify/mysql

2安装mysql数据库

3sandbox参数

make_sandbox:最简单创建sandbox
low_level_make_sandbox:创建单个sandbox,微调选项但不直接使用

make_replication_sandbox:创建master-slave架构

make_multiple_sandbox:创建相同版本的sandbox

make_multiple_custom_sandbox:创建不同版本的sandbox

make_sandbox_from_source:从build目录创建一个sandbox

make_sandbox_from_intalled:从已安装的二进制文件创建一个sandbox

sbtool:sandbox管理工具

4创建一个单一的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

你可以通过调用在sandbox文件下面的use脚本进行操作。

[root@localhost ~]# $HOME/sandboxes/msb_5_6_17/useWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3Server 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)) >

你可以管理你的sandbox通过start/stop/restart/status

创建一个主从复制架构

为了创建一个主从复制架构拓扑(默认的是1个主,2个从但是你可以通过改变参数--how_many_nodes)

我们用make_replication_sandbox命令

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

如果要登录到主的客户端的,在$HOME/sandboxes/rsandbox_mysql-5_6_23/master中 有个use脚本,运行该脚本就可以登录到主的客户端。

如果要登录到从的客户端,在$HOME/sandboxes/rsandbox_mysql-5_6_23/有node1,node2 2个文件夹,在文件夹中有use的脚本,运行该脚本就可以登录到从的客户端。

在replication sandbox,你可管理个别的sandbox通过运行start/stop/restart/status脚本在node/master文件夹中,也可以同时对它们进行管理,在$HOME/sandboxes/rsandbox_mysql-5_6_23文件夹中有restart_all,start_all,status_all,stop_all.

创建一个多主的replication

创建一个多主的sandbox 我们可以在make_replicaton_sandbox加上一个--master_master选项

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

你可以通过help参数来查看一下选项的功能:make_multiple_custom_sandbox make_multiple_sandbox make_replication_sandbox make_sandbox make_sandbox_from_installed and make_sandbox_from_source