MySQL Sandbox安装使用

MySQL Sandbox是一个非常简单快捷部署隔离的MySQL服务的一个工具。程序是用perl语言写的,有兴趣可以去读读。
可以在同一台服务器上,快速的部署一个到多个相互隔离互不影响的mysqld服务。比如,开发人员要测试程序系统的不需要在mysql的安装上纠缠过多。对新版本的一些特性感兴趣,尽可能快速结束安装部署。最短时间部署数据库应用架构如Replication Cluster进行性能测试。
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_installed : 从已安装的二进制文件创建一个sandbox
sbtool : sandbox管理工具
具体用法参考源码目录下的README文档,非常详细。

wget https://launchpad.net/mysql-sandbox/mysql-sandbox-3/mysql-sandbox-3/+download/MySQL-Sandbox-3.0.25.tar.gz

tar zxvf MySQL-Sandbox-3.0.25.tar.gz -C ../software/

tar zxvf MySQL-Sandbox-3.0.25.tar.gz -C /soft

[root@localhost MySQL-Sandbox-3.0.66]# make
cp lib/MySQL/Sandbox/Scripts.pm blib/lib/MySQL/Sandbox/Scripts.pm
cp lib/MySQL/Sandbox/Recipes.pm blib/lib/MySQL/Sandbox/Recipes.pm
cp lib/MySQL/Sandbox.pm blib/lib/MySQL/Sandbox.pm
cp bin/deploy_to_remote_sandboxes.sh blib/script/deploy_to_remote_sandboxes.sh
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/deploy_to_remote_sandboxes.sh
cp bin/msandbox blib/script/msandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/msandbox
cp bin/make_replication_sandbox blib/script/make_replication_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_replication_sandbox
cp bin/make_multiple_sandbox blib/script/make_multiple_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_multiple_sandbox
cp bin/test_sandbox blib/script/test_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/test_sandbox
cp bin/make_sandbox blib/script/make_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_sandbox
cp bin/make_sandbox_from_installed blib/script/make_sandbox_from_installed
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_sandbox_from_installed
cp bin/low_level_make_sandbox blib/script/low_level_make_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/low_level_make_sandbox
cp bin/msb blib/script/msb
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/msb
cp bin/make_multiple_custom_sandbox blib/script/make_multiple_custom_sandbox
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_multiple_custom_sandbox
cp bin/sbtool blib/script/sbtool
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/sbtool
cp bin/make_sandbox_from_source blib/script/make_sandbox_from_source
/usr/bin/perl -MExtUtils::MY -e ‘MY->fixin(shift)’ – blib/script/make_sandbox_from_source
Manifying blib/man3/MySQL::Sandbox::Scripts.3pm
Manifying blib/man3/MySQL::Sandbox::Recipes.3pm
Manifying blib/man3/MySQL::Sandbox.3pm
[root@localhost MySQL-Sandbox-3.0.66]# make test
PERL_DL_NONLAZY=1 /usr/bin/perl “-MExtUtils::Command::MM” “-e” “test_harness(0, ‘blib/lib’, ‘blib/arch’)” t/*.t
t/01_modules.t …………………. ok
t/02_test_binaries.t ……………. ok
t/03_test_sandbox.t …………….. ok
t/04_test_sbtool.t ……………… ok
t/05_test_smoke.t ………………. ok
t/06_test_user_defined.t ………… ok
t/07_test_user_defined.t ………… ok
t/08_test_single_port_checking.t …. ok
t/09_test_multiple_port_checking.t .. ok
t/10_check_start_restart.t ………. ok
t/11_replication_parameters.t ……. ok
t/12_custom_user_pwd.t ………….. ok
t/13_innodb_plugin_install.t …….. # Skipping version 5.6.25 for this test. It is not in the required range (5.1.6 - 5.1.99)
t/13_innodb_plugin_install.t …….. ok
t/14_semi_synch_plugin_install.t …. ok
t/15_user_privileges.t ………….. ok
t/16_replication_options.t ………. ok
t/17_replication_flow.t …………. ok
t/18_force_creation.t …………… ok
t/19_replication_gtid.t …………. ok
t/20_add_option.t ………………. ok
All tests successful.
Files=20, Tests=57, 2 wallclock secs ( 0.12 usr 0.10 sys + 1.42 cusr 0.27 csys = 1.91 CPU)
Result: PASS
[root@localhost MySQL-Sandbox-3.0.66]# make install
Installing /usr/local/share/perl5/MySQL/Sandbox.pm
Installing /usr/local/share/perl5/MySQL/Sandbox/Recipes.pm
Installing /usr/local/share/perl5/MySQL/Sandbox/Scripts.pm
Installing /usr/local/share/man/man3/MySQL::Sandbox::Recipes.3pm
Installing /usr/local/share/man/man3/MySQL::Sandbox.3pm
Installing /usr/local/share/man/man3/MySQL::Sandbox::Scripts.3pm
Installing /usr/local/bin/make_replication_sandbox
Installing /usr/local/bin/make_sandbox_from_source
Installing /usr/local/bin/sbtool
Installing /usr/local/bin/make_sandbox
Installing /usr/local/bin/low_level_make_sandbox
Installing /usr/local/bin/test_sandbox
Installing /usr/local/bin/make_multiple_sandbox
Installing /usr/local/bin/deploy_to_remote_sandboxes.sh
Installing /usr/local/bin/make_sandbox_from_installed
Installing /usr/local/bin/msandbox
Installing /usr/local/bin/msb
Installing /usr/local/bin/make_multiple_custom_sandbox
Appending installation info to /usr/lib64/perl5/perllocal.pod

上传MYSQL安装包
[root@localhost msb_5_5_40]# ll /soft/
total 4266292
-rw-r–r–. 1 root root 184731768 Dec 13 18:45 mysql-5.5.40-linux2.6-x86_64.tar.gz
-rw-r–r–. 1 root root 312829487 Dec 13 18:43 mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 6 501 games 4096 Dec 13 18:41 MySQL-Sandbox-3.0.66
-rw-r–r–. 1 root root 124076 Dec 13 18:37 MySQL-Sandbox-3.0.66.tar.gz

.设置环境变量(否则会抛错)

[root@localhost ~]# echo ‘export SANDBOX_AS_ROOT=1’ >> /root/.bash_profile
[root@localhost ~]# source /root/.bash_profile

.在沙箱环境中运行我们mysql两个实例

[root@localhost mysql]# make_sandbox mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
unpacking /opt/mysql/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
Executing low_level_make_sandbox –basedir=/opt/mysql/5.6.28 \
–sandbox_directory=msb_5_6_28 \
–install_version=5.6 \
–sandbox_port=5628 \
–no_ver_after_name \
–my_clause=log-error=msandbox.err
The MySQL Sandbox, version 3.0.66
(C) 2006-2015 Giuseppe Maxia
Installing with the following parameters:
upper_directory = /root/sandboxes
sandbox_directory = msb_5_6_28
sandbox_port = 5628
check_port =
no_check_port =
datadir_from = script
install_version = 5.6
basedir = /opt/mysql/5.6.28
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) y
loading grants
.. sandbox server started
Your sandbox server was installed in $HOME/sandboxes/msb_5_6_28
最后会有安装路径的提示,默认在家目录下的sandboxes下
[root@localhost msb_5_5_40]# ll /root/sandboxes/
total 48
-rwxr-xr-x. 1 root root 54 Dec 13 18:55 clear_all
drwxr-xr-x. 4 root root 4096 Dec 13 18:54 msb_5_6_28
-rw-r–r–. 1 root root 3621 Dec 13 18:55 plugin.conf
-rwxr-xr-x. 1 root root 56 Dec 13 18:55 restart_all
-rwxr-xr-x. 1 root root 2139 Dec 13 18:55 sandbox_action
-rwxr-xr-x. 1 root root 58 Dec 13 18:55 send_kill_all
-rwxr-xr-x. 1 root root 54 Dec 13 18:55 start_all
-rwxr-xr-x. 1 root root 55 Dec 13 18:55 status_all
-rwxr-xr-x. 1 root root 53 Dec 13 18:55 stop_all
-rwxr-xr-x. 1 root root 4076 Dec 13 18:55 test_replication
-rwxr-xr-x. 1 root root 52 Dec 13 18:55 use_all

检查MYSQL进程是否已经进来
root@localhost mysql]# ps -ef|grep mysql
root 9954 1 0 18:53 pts/1 00:00:00 /bin/sh /opt/mysql/5.6.28/bin/mysqld_safe –defaults-file=/root/sandboxes/msb_5_6_28/my.sandbox.cnf
root 10144 9954 0 18:53 pts/1 00:00:00 /opt/mysql/5.6.28/bin/mysqld –defaults-file=/root/sandboxes/msb_5_6_28/my.sandbox.cnf –basedir=/opt/mysql/5.6.28 –datadir=/root/sandboxes/msb_5_6_28/data –plugin-dir=/opt/mysql/5.6.28/lib/plugin –user=root –log-error=/root/sandboxes/msb_5_6_28/data/msandbox.err –pid-file=/root/sandboxes/msb_5_6_28/data/mysql_sandbox5628.pid –socket=/tmp/mysql_sandbox5628.sock –port=5628

手动启动测试:
[root@localhost mysql]# pkill -9 mysqld
[root@localhost mysql]# ps -ef|grep mysql
root 9939 9164 0 18:53 pts/1 00:00:00 grep mysql
[root@localhost sandboxes]# cd msb_5_6_28/
[root@localhost msb_5_6_28]# ll
total 740
-rwxr-xr-x. 1 root root 1319 Dec 13 18:51 add_option
-rwxr-xr-x. 1 root root 1797 Dec 13 18:51 change_paths
-rwxr-xr-x. 1 root root 1583 Dec 13 18:51 change_ports
-rwxr-xr-x. 1 root root 2601 Dec 13 18:51 clear
-rw-r–r–. 1 root root 2336 Dec 13 18:51 connection.json
drwx——. 5 root root 4096 Dec 13 18:51 data
-rw-r–r–. 1 root root 166 Dec 13 18:51 default_connection.json
-rw-r–r–. 1 root root 1361 Dec 13 18:51 grants_5_7_6.mysql
-rw-r–r–. 1 root root 903 Dec 13 18:51 grants.mysql
-rwxr-xr-x. 1 root root 1404 Dec 13 18:51 json_in_db
-rwxr-xr-x. 1 root root 1508 Dec 13 18:51 load_grants
-rwxr-xr-x. 1 root root 1511 Dec 13 18:51 msb
-rwxr-xr-x. 1 root root 1899 Dec 13 18:51 my
-rwxr-xr-x. 1 root root 1199 Dec 13 18:51 mycli
-rw-r–r–. 1 root root 1629 Dec 13 18:51 my.sandbox.cnf
-rwxr-xr-x. 1 root root 913 Dec 13 18:51 proxy_start
-rw-r–r–. 1 root root 1140 Dec 13 18:51 README
-rw-r–r–. 1 root root 646319 Dec 13 18:51 rescue_mysql_dump.sql
-rwxr-xr-x. 1 root root 972 Dec 13 18:51 restart
-rwxr-xr-x. 1 root root 1757 Dec 13 18:51 send_kill
-rwxr-xr-x. 1 root root 2189 Dec 13 18:51 show_binlog
-rwxr-xr-x. 1 root root 2423 Dec 13 18:51 show_relaylog
-rwxr-xr-x. 1 root root 2724 Dec 13 18:51 start
-rwxr-xr-x. 1 root root 1242 Dec 13 18:51 status
-rwxr-xr-x. 1 root root 1834 Dec 13 18:51 stop
drwxr-xr-x. 2 root root 4096 Dec 13 18:51 tmp
-rwxr-xr-x. 1 root root 1455 Dec 13 18:51 use
-rw-r–r–. 1 root root 86 Dec 13 18:51 USING
[root@localhost msb_5_6_28]# ./start
.. sandbox server started

如何使用mysql:
[root@localhost msb_5_6_28]# ./use
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.

同样其它版本采用相同步骤

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值