一 sandbox是什么?
MySQL Sandbox是一个非常简单快捷部署隔离的MySQL服务的一个工具。程序是用perl语言写的,作者用go语言重构,新的项目名叫dbdeployer。不过不要紧,Sandbox依然支持3.23到8.0的任何版本的MySQL(以及任何版本的MariaDB)下的功能。
项目地址:
https://github.com/datacharmer/mysql-sandbox
二 如何安装
有网络就直接采用cpan来安装,没有网络童鞋也可以下载源码后编译安装了。
1.安装cpan
yum install cpan -y
2.安装软件依赖包
yum install perl-Test-Simple -y
3.安装MySQL
Sandbox
cpan MySQL::Sandbox
全程默认回车就好了,安装时间适网络环境而定,中间可能会对cpan版本升级及寻找可用镜像。
直至最后看到/usr/bin/make install -- OK字样表示安装完成
4.设置环境变量
echo 'export SANDBOX_AS_ROOT=1' >> /root/.bash_profile
source /root/.bash_profile
三 简单使用
安装完成之后,默认会在 /root/perl5/bin/ 目录下产生make_开头的文件
ll /root/perl5/bin/
make_multiple_custom_sandbox # 创建不同版本的MySQL实例
make_multiple_sandbox # 创建多个相同版本的MySQL实例
make_replication_sandbox # 搭建主从结构复制结构MySQL实例,可以是一主一从,也可以是一组多从
make_sandbox # 基于二进制压缩包创建MySQL实例
make_sandbox_from_installed # 基于已安装好的mysql可执行文件目录安装MySQL实例
make_sandbox_from_source # 基于源码创建MySQL实例,需要带两个参数
make_sandbox_from_url # 从网上下载docker镜像进行安装,具体参考 --help 命令
sbtool # sandbox管理工具
具体用法参考源码目录下的README文档,非常详细。
我们去MySQL官网下载一个二进制包来测试下
MySQL下载地址:
https://downloads.mysql.com/archives/community/
PS:使用迅雷下载速度杠杠的
四 测试
使用sandbox安装单个实例
make_sandbox /tmp/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
unpacking /tmp/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
Executing low_level_make_sandbox --basedir=/tmp/5.7.30
--sandbox_directory=msb_5_7_30
--install_version=5.7
--sandbox_port=5730
--no_ver_after_name
--my_clause=log-error=msandbox.err
The MySQL Sandbox, version 3.2.18
(C) 2006-2018 Giuseppe Maxia
Installing with the following parameters:
upper_directory = /root/sandboxes
sandbox_directory = msb_5_7_30
sandbox_port = 5730
check_port =
no_check_port =
datadir_from = script
install_version = 5.7
basedir = /tmp/5.7.30
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
。。。省略部分。。。
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 =
keep_auth_plugin =
history_dir =
do you agree? ([Y],n) y # 输入y确认,然后sandbox就会按上面的参数启动一个实例
# Starting server
...... sandbox server started
# Loading grants
Your sandbox server was installed in $HOME/sandboxes/msb_5_7_30
安装完成,最后一句话告诉我们生成的实例安装在当前用户家目录下的 /sandboxes/msb_5_7_30 目录下
大家可以看下这些可执行文件具体内容,都是shell脚本写的
登陆数据库测试
[root@sandbox msb_5_7_30]# ./use
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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)) > show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
接下来我们基于刚才创建的实例解压出来的源程序目录(/tmp/5.7.30)构建主从
make_replication_sandbox --gtid --how_many_slave=1 /tmp/5.7.30
--gtid # 指定gtid方式构建主从
--how_many_slave=1 # 需要构建从库的数量,不指定时默认创建一主两从的环境
/tmp/5.7.30 # 指定一个已经解压的二进制目录,当然也可以是源码的压缩包
installing and starting master
installing slave 1
starting slave 1
... sandbox server started
initializing slave 1
replication directory installed in $HOME/sandboxes/rsandbox_5_7_30
根据结果提示sandbox创建的主从目录在 $HOME/sandboxes/rsandbox_5_7_30 我们 cd 进去看下
其中 master 和 node1 分别是主库和备库的数据库目录, m 和 n1 都是登陆主库的命令,s1 和 n2 都是登陆从库的命令,其他的可以从文件名知道具体用途。这里介绍两个命令test_replication和check_slaves 两个命令功能类似,都是检查slave 的状态信息。check_slaves会调用’show slave statusG’,其它可执行文件根据字面意思去理解就可以,也都是shell脚本写的。
本文由 @程亚楠[Vip] 发布于 职涯宝 ,未经作者许可,禁止转载,欢迎您分享文章