sandbox的安装可以使用github的方式,也可以使用cpan安装。
推荐使用cpan这种一键安装的。
# 安装mysqlsanbox
yum install cpan perl-YAML perl-Test-Simple -ycpan MySQL::Sandboxecho ‘export SANDBOX_AS_ROOT=1‘ >> /root/.bashrc source /root/.bashrc
将准备好的几个常用mysql通用二进制包放到/opt/目录下。如下:
[[email protected] /opt ]# lltotal 1035444-rw-r--r-- 1 root root 640650826 2017-07-27 20:53 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz-rw-r--r-- 1 root root 419634124 2017-07-27 20:53 mariadb-10.3.0-linux-x86_64.tar.gz
创建一个10.3.0版本的mariadb实例
make_sandbox mariadb-10.3.0-linux-x86_64.tar.gz
过程如下:unpacking /opt/mariadb-10.3.0-linux-x86_64.tar.gz
Executing low_level_make_sandbox --basedir=/opt/10.3.0 \
--sandbox_directory=msb_10_3_0 \
--install_version=10.3 \
--sandbox_port=10300 \
--no_ver_after_name \
--my_clause=log-error=msandbox.err
The MySQL Sandbox, version 3.2.13
(C) 2006-2017 Giuseppe Maxia
Installing with the following parameters:
upper_directory = /root/sandboxes
sandbox_directory = msb_10_3_0
sandbox_port = 10300
check_port =
no_check_port =
datadir_from = script
install_version = 10.3
basedir = /opt/10.3.0
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
init_options =
init_my_cnf =
init_use_cnf =
master =
slaveof =
high_performance =
gtid =
pre_start_exec =
pre_grants_exec =
post_grants_exec =
pre_grants_sql =
post_grants_sql =
pre_grants_file =
post_grants_file =
load_plugin =
plugin_mysqlx =
mysqlx_port =
expose_dd_tables =
custom_mysqld =
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 =
keep_uuid =
history_dir =
do you agree? ([Y],n) y
# Starting server
.. sandbox server started
# Loading grants
Your sandbox server was installed in $HOME/sandboxes/msb_10_3_0
然后,输入Y表示同意上面的配置参数。
稍等20s后,就会自动在/root/sandboxes目录下生成一个类似msb_10_3_0的目录
默认是监听在127.0.0.1的地址的。如果我们要改成监听在外部地址的话,
cd /root/sandboxes/msb_10_3_0 (这个目录下有很多脚本,可以自己看下里面内容就知道如何用了)
vim /root/sandboxes/msb_10_3_0/my.sandbox.cnf 注释掉listen那行代码,
然后执行./restart 即可。
./use 即可登录mysql
./mycli 就可以用mycli来登录(CentOS6需要自己编译安装python27才能正常使用mycli)
创建一套GTID复制的5.7.19主从实例
cd /opt/ ### 需要先切换到mysql源码包那个路径下才行 make_replication_sandbox --gtid --how_many_slaves=1 5.7.19 创建一套GTID复制的5.7.19主从实例
稍等20s,即可启动1套主从mysql5.7.19的环境。
ss -lntp|grep mysql 即可验证。
如何使用上面创建的GTID主从机器:
cd /root/sandboxes cd rsandbox_5_7_19 [[email protected] /root/sandboxes/rsandbox_5_7_19 ]# ./test_replication 检查主从复制状态
# Master log: mysql-bin.000001 - Position: 11309 - Rows: 20
# Testing slave #1
ok - Slave #1 acknowledged reception of transactions from master
ok - Slave #1 IO thread is running
ok - Slave #1 SQL thread is running
ok - Table t1 found on slave #1
ok - Table t1 has 20 rows on #1
# TESTS : 5
# FAILED: 0 ( 0.0%)
# PASSED: 5 (100.0%)
# exit code: 0
这个目录下,m和n1都是连接主库的连接脚本。 s1和n2都是连接从库的脚本。
#####################################
如果需要一次性建立好几个相同的实例且不需要有复制关系,可以使用下面的命令
cd /opt/ make_multiple_sandbox --how_many_nodes=3 mariadb-10.3.0-linux-x86_64.tar.gz # 默认一次性建立3个实例
#####还有些常用的命令,都是些简单的shell脚本,打开看下就知道啥意思了。就不解释了。