MySQL Sandbox安装使用

下面教大家如何利用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
 total 588236
 -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,  version 3.0.44
    (C) 2006-2013 Giuseppe Maxia
installing with the following parameters:
upper_directory                = /root/sandboxes
sandbox_directory              = msb_5_6_19
sandbox_port                   = 5619
check_port                     = 
no_check_port                  = 
datadir_from                   = script
install_version                = 5.6
basedir                        = 5.6.19
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或者回车,如果按了后报如下的错:

/root/5.6.19/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
如果有以上的报错,则yum install libaio -y,没有就跳过

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

do you agree? ([Y],n) y
loading grants
.... sandbox server started
Your sandbox server was installed in $HOME/sandboxes/msb_5_6_19
[root@localhost]# 

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

[root@localhost sandboxes]# pwd
/root/sandboxes
[root@localhost sandboxes]# ll
total 40
-rwxr-xr-x. 1 root root   54 Jun  4 05:25 clear_all
drwxr-xr-x. 4 root root 4096 Jun  4 05:25 msb_5_6_19
-rw-r--r--. 1 root root 3621 Jun  4 05:25 plugin.conf
-rwxr-xr-x. 1 root root   56 Jun  4 05:25 restart_all
-rwxr-xr-x. 1 root root 2139 Jun  4 05:25 sandbox_action
-rwxr-xr-x. 1 root root   58 Jun  4 05:25 send_kill_all
-rwxr-xr-x. 1 root root   54 Jun  4 05:25 start_all
-rwxr-xr-x. 1 root root   55 Jun  4 05:25 status_all
-rwxr-xr-x. 1 root root   53 Jun  4 05:25 stop_all
-rwxr-xr-x. 1 root root   52 Jun  4 05:25 use_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:24 change_paths
-rwxr-xr-x 1 root root   1583 12月 25 04:24 change_ports
-rwxr-xr-x 1 root root   2283 12月 25 04:24 clear
-rw-r--r-- 1 root root   2326 12月 25 04:24 connection.json
drwx------ 5 root root   4096 12月 25 04:33 data
-rw-r--r-- 1 root root    166 12月 25 04:24 default_connection.json
-rw-r--r-- 1 root root    869 12月 25 04:24 grants.mysql
-rwxr-xr-x 1 root root   1196 12月 25 04:24 json_in_db
-rwxr-xr-x 1 root root   1270 12月 25 04:24 load_grants
-rwxr-xr-x 1 root root   1511 12月 25 04:24 msb
-rwxr-xr-x 1 root root   1894 12月 25 04:24 my
-rw-r--r-- 1 root root   1597 12月 25 04:24 my.sandbox.cnf
-rwxr-xr-x 1 root root    913 12月 25 04:24 proxy_start
-rw-r--r-- 1 root root   1135 12月 25 04:24 README
-rw-r--r-- 1 root root 608666 12月 25 04:25 rescue_mysql_dump.sql
-rwxr-xr-x 1 root root    972 12月 25 04:24 restart
-rwxr-xr-x 1 root root   1501 12月 25 04:24 send_kill
-rwxr-xr-x 1 root root   2463 12月 25 04:24 start
-rwxr-xr-x 1 root root   1093 12月 25 04:24 status
-rwxr-xr-x 1 root root   1618 12月 25 04:24 stop
drwxr-xr-x 2 root root   4096 12月 25 04:33 tmp
-rwxr-xr-x 1 root root   1390 12月 25 04:24 use
-rw-r--r-- 1 root root     81 12月 25 04:24 USING

复制代码

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

[root@localhost msb_5_6_19]# pkill -9 mysqld
[root@localhost msb_5_6_19]# ./start 
 sandbox server already started (found pid file /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 connection id is 2
Server version: 5.6.19 MySQL 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 clear the 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 node 1

installing node 2

installing node 3

执行好后会生成一个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:45 clear_all
drwxr-xr-x 4 root root 4096 12月 25 05:45 msb_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:45 plugin.conf
-rwxr-xr-x 1 root root   56 12月 25 04:45 restart_all
-rwxr-xr-x 1 root root 2139 12月 25 04:45 sandbox_action
-rwxr-xr-x 1 root root   58 12月 25 04:45 send_kill_all
-rwxr-xr-x 1 root root   54 12月 25 04:45 start_all
-rwxr-xr-x 1 root root   55 12月 25 04:45 status_all
-rwxr-xr-x 1 root root   53 12月 25 04:45 stop_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:46 check_slaves
-rwxr-xr-x 1 root root  456 12月 25 04:46 clear_all
-rw-r--r-- 1 root root 7772 12月 25 04:46 connection.json
-rw-r--r-- 1 root root  626 12月 25 04:46 default_connection.json
-rwxr-xr-x 1 root root   54 12月 25 04:46 n1
-rwxr-xr-x 1 root root   54 12月 25 04:46 n2
-rwxr-xr-x 1 root root   54 12月 25 04:46 n3
drwxr-xr-x 4 root root 4096 12月 25 04:47 node1
drwxr-xr-x 4 root root 4096 12月 25 04:47 node2
drwxr-xr-x 4 root root 4096 12月 25 04:47 node3
-rw-r--r-- 1 root root 1088 12月 25 04:46 README
-rwxr-xr-x 1 root root  216 12月 25 04:46 restart_all
-rwxr-xr-x 1 root root  484 12月 25 04:46 send_kill_all
-rwxr-xr-x 1 root root  456 12月 25 04:46 start_all
-rwxr-xr-x 1 root root  235 12月 25 04:46 status_all
-rwxr-xr-x 1 root root  449 12月 25 04:46 stop_all
-rwxr-xr-x 1 root root  321 12月 25 04:46 use_all

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

 

作者:陆炫志

出处:xuanzhi的博客 http://www.cnblogs.com/xuanzhi201111

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

posted @ 2014-09-28 17:05  GoogSQL  阅读(1613)  评论(0编辑  收藏  举报