mysql sandbox_MySQL Sandbox安装使用

颜志业
2023-12-01

下面教大家如何利用MySQL  Sandbox迅速搭建多个mysql实例。MySQL Sandbox是什么呢?简单来说就是一个沙盒,可以用于快速搭建mysql的环境,让我们可以不用费劲的去安装,或者编译,通常对于学习来说是不错的选择,这案例是方便自己学习和练习使用,而非线上环境。项目主页:http://mysqlsandbox.net/

下面是我的搭建过程:

1.安装cpan

yum install cpan -y

2.安装软件依赖的包

yum install perl-Test-Simple -y

3.安装MySQL Sandbox

cpan MySQL::Sandbox

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

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

[root@localhost~]# source /root/.bash_profile

5.下载mysql二进制软件包(我这里下载mysql5.6,建议大家要养成去官网下载软件包的习惯,我这里已经下载,如下)

下载链接:http://dev.mysql.com/downloads/mysql/

[root@localhost]# pwd

/root

[root@localhost]# ll

total588236

-rw-r--r-- 1 root root 305545110 7月 13 2014 mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz

[root@localhost]#

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

开始安装的工作:

[root@localhost]# make_sandbox mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz

成功安装后最后会显示:

unpacking /root/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz

Executing low_level_make_sandbox--basedir=/root/5.6.19\--sandbox_directory=msb_5_6_19 \--install_version=5.6\--sandbox_port=5612\--no_ver_after_name \--my_clause=log-error=msandbox.err

The MySQL Sandbox, version3.0.44(C)2006-2013Giuseppe Maxia

installing with the following parameters:

upper_directory= /root/sandboxes

sandbox_directory=msb_5_6_19

sandbox_port= 5619check_port=no_check_port=datadir_from=script

install_version= 5.6basedir= 5.6.19tmpdir=my_file=operating_system_user=root

db_user=msandbox

remote_access= 127.%bind_address= 127.0.0.1ro_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= 1verbose=load_grants= 1no_load_grants=no_run=no_show=

do you agree? ([Y],n)

到这里后,请按Y或者回车,如果按了后报如下的错:

/root/5.6.19/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such fileor directory

如果有以上的报错,则yuminstall libaio -y,没有就跳过

按下Y后,出现以下的信息,就证明你安装成功了:

do you agree?([Y],n) y

loading grants

.... sandbox server started

Your sandbox server was installedin $HOME/sandboxes/msb_5_6_19

[root@localhost]#

最后会有安装路径的提示,默认在家目录下的sandboxes下。我们可以看看

[root@localhost sandboxes]# pwd

/root/sandboxes

[root@localhost sandboxes]# ll

total40

-rwxr-xr-x. 1 root root 54 Jun 4 05:25clear_all

drwxr-xr-x. 4 root root 4096 Jun 4 05:25msb_5_6_19-rw-r--r--. 1 root root 3621 Jun 4 05:25plugin.conf-rwxr-xr-x. 1 root root 56 Jun 4 05:25restart_all-rwxr-xr-x. 1 root root 2139 Jun 4 05:25sandbox_action-rwxr-xr-x. 1 root root 58 Jun 4 05:25send_kill_all-rwxr-xr-x. 1 root root 54 Jun 4 05:25start_all-rwxr-xr-x. 1 root root 55 Jun 4 05:25status_all-rwxr-xr-x. 1 root root 53 Jun 4 05:25stop_all-rwxr-xr-x. 1 root root 52 Jun 4 05:25use_all

[root@localhost sandboxes]#

在安装好后,就已经默认启动了的,可以杀掉进程,自己启动看看,启动停止脚本在/root/sandboxes/msb_5_6_19

[root msb_5_6_19]# ll

总用量684

-rwxr-xr-x 1 root root 1797 12月 25 04:24change_paths-rwxr-xr-x 1 root root 1583 12月 25 04:24change_ports-rwxr-xr-x 1 root root 2283 12月 25 04:24 clear

-rw-r--r-- 1 root root 2326 12月 25 04:24connection.json

drwx------ 5 root root 4096 12月 25 04:33data-rw-r--r-- 1 root root 166 12月 25 04:24default_connection.json-rw-r--r-- 1 root root 869 12月 25 04:24grants.mysql-rwxr-xr-x 1 root root 1196 12月 25 04:24json_in_db-rwxr-xr-x 1 root root 1270 12月 25 04:24load_grants-rwxr-xr-x 1 root root 1511 12月 25 04:24msb-rwxr-xr-x 1 root root 1894 12月 25 04:24my-rw-r--r-- 1 root root 1597 12月 25 04:24my.sandbox.cnf-rwxr-xr-x 1 root root 913 12月 25 04:24proxy_start-rw-r--r-- 1 root root 1135 12月 25 04:24README-rw-r--r-- 1 root root 608666 12月 25 04:25rescue_mysql_dump.sql-rwxr-xr-x 1 root root 972 12月 25 04:24restart-rwxr-xr-x 1 root root 1501 12月 25 04:24send_kill-rwxr-xr-x 1 root root 2463 12月 25 04:24start-rwxr-xr-x 1 root root 1093 12月 25 04:24status-rwxr-xr-x 1 root root 1618 12月 25 04:24stop

drwxr-xr-x 2 root root 4096 12月 25 04:33tmp-rwxr-xr-x 1 root root 1390 12月 25 04:24use-rw-r--r-- 1 root root 81 12月 25 04:24USING

复制代码

启动执行./start,关闭执行./stop,登录./use

[root@localhost msb_5_6_19]# pkill -9mysqld

[root@localhost msb_5_6_19]# ./start

sandbox server already started (found pidfile /root/sandboxes/msb_5_6_19/data/mysql_sandbox5612.pid)

sandbox server started

[root@localhost msb_5_6_19]#rm -f /root/sandboxes/msb_5_6_19/data/mysql_sandbox5612.pid

[root@localhost msb_5_6_19]# ./start

. sandbox server started

[root@localhost msb_5_6_19]#

[root@localhost msb_5_6_19]# ./use

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 2Server version:5.6.19MySQL Community Server (GPL)

Copyright (c)2000, 2013, 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 clearthe current input statement.

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

以上的一个MySQL Sandbox的环境已经安装好了

下面安装多个实例:

可以执行make_multiple_sandbox --help查看一个其使用情况

默认3个节点,那就意思是三个实例

[root@localhost]# make_multiple_sandbox mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz

installing node1installing node2installing node3

执行好后会生成一个multi_msb_mysql-5_6_19的文件夹:

[root sandboxes]# pwd

/root/sandboxes

[root sandboxes]# ll

总用量44

-rwxr-xr-x 1 root root 54 12月 25 04:45clear_all

drwxr-xr-x 4 root root 4096 12月 25 05:45msb_5_6_19

drwxr-xr-x 5 root root 4096 12月 25 04:46 multi_msb_mysql-5_6_19-rw-r--r-- 1 root root 3621 12月 25 04:45plugin.conf-rwxr-xr-x 1 root root 56 12月 25 04:45restart_all-rwxr-xr-x 1 root root 2139 12月 25 04:45sandbox_action-rwxr-xr-x 1 root root 58 12月 25 04:45send_kill_all-rwxr-xr-x 1 root root 54 12月 25 04:45start_all-rwxr-xr-x 1 root root 55 12月 25 04:45status_all-rwxr-xr-x 1 root root 53 12月 25 04:45stop_all-rwxr-xr-x 1 root root 52 12月 25 04:45 use_all

进到目录multi_msb_mysql-5_6_19里,可以看到有n1,n2,n3,这就是三个实例:

[root multi_msb_mysql-5_6_19]# ll

总用量72

-rwxr-xr-x 1 root root 377 12月 25 04:46check_slaves-rwxr-xr-x 1 root root 456 12月 25 04:46clear_all-rw-r--r-- 1 root root 7772 12月 25 04:46connection.json-rw-r--r-- 1 root root 626 12月 25 04:46default_connection.json-rwxr-xr-x 1 root root 54 12月 25 04:46n1-rwxr-xr-x 1 root root 54 12月 25 04:46n2-rwxr-xr-x 1 root root 54 12月 25 04:46n3

drwxr-xr-x 4 root root 4096 12月 25 04:47node1

drwxr-xr-x 4 root root 4096 12月 25 04:47node2

drwxr-xr-x 4 root root 4096 12月 25 04:47node3-rw-r--r-- 1 root root 1088 12月 25 04:46README-rwxr-xr-x 1 root root 216 12月 25 04:46restart_all-rwxr-xr-x 1 root root 484 12月 25 04:46send_kill_all-rwxr-xr-x 1 root root 456 12月 25 04:46start_all-rwxr-xr-x 1 root root 235 12月 25 04:46status_all-rwxr-xr-x 1 root root 449 12月 25 04:46stop_all-rwxr-xr-x 1 root root 321 12月 25 04:46 use_all

登录分别是./n1 ./n2  ./n3 ;重启、关闭、启动应该大家也能看到了,多实例就搭建好了

作者:陆炫志

您的支持是对博主最大的鼓励,感谢您的认真阅读。本文版权归作者所有,欢迎转载,但请保留该声明。

 类似资料: