ここでの動作環境は次のとおり。

  • OS: Mac OS X 10.5.7
  • MySQL Sandbox: 3.0.04
  • MySQL: 5.1.36

まずはMySQL Sandbox本体のインストールだ。rootユーザならばCPAN経由でのインストールが手っ取り早い。

CPAN経由でMySQL Sandboxをインストール

# cpan
cpan> install MySQL::Sandbox

一般ユーザならばlaunchpad.netからソースパッケージを入手してインストールする。

ソースパッケージを解凍してmake後、インストール

$ tar -xzf MySQL-Sandbox-3.0.04.tar.gz
$ cd MySQL-Sandbox-3.0.04/
$ perl Makefile.PL PREFIX=$HOME/usr/local
$ make
$ make test
$ make install

MySQL Sandboxの本体一式は$HOME/usr以下にデプロイされ、$HOME以下にsandboxesディレクトリが作成される。

続けてMySQL本体のインストールをMySQL Sandboxを使用して行う。まずは簡単にひとつだけ(single sandbox)構築するパターンだ。MySQL Downloadsからインストールしたいソースパッケージをダウンロードし、$HOME/opt/mysql/以下に配置したあとmake_sandboxを行う。

make_sandboxでMySQLをインストール

$ export PERL4LIB=~/usr/local/lib/perl5/site_perl/
$ make_sandbox $HOME/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz
unpacking /Users/hiroaki/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz
Executing low_level_make_sandbox --basedir=/Users/hiroaki/opt/mysql/5.1.36 \
        --sandbox_directory=msb_5_1_36 \
        --install_version=5.1 \
        --sandbox_port=5136 \
        --no_ver_after_name \
        --my_clause=log-error=msandbox.err
    The MySQL Sandbox,  version 3.0.04
    (C) 2006,2007,2008,2009 Giuseppe Maxia
installing with the following parameters:
upper_directory                = /Users/hiroaki/sandboxes
sandbox_directory              = msb_5_1_36
sandbox_port                   = 5136
check_port                     = 0
no_check_port                  = 0
datadir_from                   = script
install_version                = 5.1
basedir                        = /Users/hiroaki/opt/mysql/5.1.36
my_file                        = 
operating_system_user          = hiroaki
db_user                        = msandbox
db_password                    = msandbox
my_clause                      = log-error=msandbox.err
prompt_prefix                  = mysql
prompt_body                    =  [\h] {\u} (\d) > '
force                          = 0
no_ver_after_name              = 1
verbose                        = 0
load_grants                    = 1
no_load_grants                 = 0
no_show                        = 0
do you agree? ([Y],n) y
loading grants
.. sandbox server started
Your sandbox server was installed in $HOME/sandboxes/msb_5_1_36

makesandbox後に入力した箇所は、確認箇所(do you agree? ([Y], n))の「y」だけだ。sandboxベースディレクトリや使用するポートはMySQLのバージョンから判別され、自動的に決定される。makesandboxを実行するだけでsandboxが$HOME/sandboxes/以下にデプロイされるのだ。makesandbox実行時に--checkportオプションを指定すれば既存のsandboxディレクトリ名やポートと競合していないかチェックがおこなわれる。また、sandboxベースディレクトリやポート番号といった情報を適宜変更してデプロイしたい場合はmake_sandbox実行時に--interactiveオプションを指定すればOKだ。

--interactiveオプションを指定してmake_sandboxを実行。対話式インストールとなる

$ make_sandbox $HOME/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz --interactive
unpacking /Users/hiroaki/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz
Executing low_level_make_sandbox --basedir=/Users/hiroaki/opt/mysql/5.1.36 \
    --sandbox_directory=msb_5_1_36 \
    --install_version=5.1 \
    --sandbox_port=5136 \
    --no_ver_after_name \
    --interactive \
    --my_clause=log-error=msandbox.err
Enter the values for each option
* To leave the interactive choice and accept default values 
     for the remaining options, enter 'default'
* To go to the previous item, enter 'back'
* To quit the installation without any action, enter 'quit'

-----------------------------------------------------------------
upper_directory
   The directory that will contain the sandbox. (default: $SANDBOX_HOME (/Users/hiroaki/sandboxes)) 
Your choice: (current value [/Users/hiroaki/sandboxes]) 
-----------------------------------------------------------------
sandbox_directory
   Where to install the sandbox, under upper-directory 
Your choice: (current value [msb_5_1_36]) 
-----------------------------------------------------------------
sandbox_port
   The port number to use for the sandbox server. 
   (Default: 3310) 
Your choice: (current value [5136]) 
-----------------------------------------------------------------
check_port
   Check whether the provided port is free, 
   and determine the next available one if it is not. 
   (Default: disabled) 
Your choice: (current value [0]) 
-----------------------------------------------------------------
datadir_from
   Where to get datadir files from. Available options are 
   archive   will be taken from the archived data 
             provided with the package. They include 
             default username and passwords 
             ( DEPRECATED ) 
   script    the script mysql_install_db is called, with 
             default users, no passwords. 
   dir:name  will be copied from an existing mysql directory 
   (Default: script) 
Your choice: (current value [script]) 
-----------------------------------------------------------------
install_version
   Which version to install (3.23, 4.0, 4.1, 5.0 or 5.1) default: none 
Your choice: (current value [5.1]) 
-----------------------------------------------------------------
basedir
   Base directory for MySQL (default: /usr/local/mysql) 
Your choice: (current value [/Users/hiroaki/opt/mysql/5.1.36]) 
-----------------------------------------------------------------
my_file
   which sample my-{small|large|huge}.cnf file should be used 
   for additional configuration 
   You may enter either the label (small|large|huge) or a full 
   file name. (default: none) 
Your choice: (current value []) 
-----------------------------------------------------------------
conf_file
   Configuration file containing options like the ones 
   you can give on the command line (without dashes) 
Your choice: (current value []) 
-----------------------------------------------------------------
operating_system_user
   Operating system user (for mysql installation) 
   default: $USER (hiroaki) 
Your choice: (current value [hiroaki]) 
-----------------------------------------------------------------
db_user
   user for global access to mysql (Default: sandbox) 
Your choice: (current value [msandbox]) 
-----------------------------------------------------------------
db_password
   password for global access to mysql (Default: sandbox) 
Your choice: (current value [msandbox]) 
-----------------------------------------------------------------
my_clause
   option to be inserted in a my.cnf file 
   it may be used several times 
Your choice: (current value [log-error=msandbox.err]) (You can enter multiple values separated by ';') 
-----------------------------------------------------------------
prompt_prefix
   prefix to use in CLI prompt (default: mysql) 
Your choice: (current value [mysql]) 
-----------------------------------------------------------------
prompt_body
   options to use in CLI prompt (default:  [\h] {\u} (\d) > ) 
Your choice: (current value [ [\h] {\u} (\d) > ']) 
-----------------------------------------------------------------
force
   Use this option if you want to overwrite existing directories 
   and files during the installation. (Default: disabled) 
Your choice: (current value [0]) 
-----------------------------------------------------------------
no_ver_after_name
   Do not add version number after sandbox directory name (default: disabled) 
Your choice: (current value [1]) 
-----------------------------------------------------------------
verbose
   Use this option to see installation progress (default: disabled) 
Your choice: (current value [0]) 
-----------------------------------------------------------------
load_grants
   Loads the predefined grants from a SQL file. 
   Useful when installing from script. 
   (default: disabled) 
Your choice: (current value [0]) 
-----------------------------------------------------------------
no_confirm
   suppress the confirmation request from user 
Your choice: (current value [0]) 
-----------------------------------------------------------------
no_show
   does not show options or ask confirmation to the user 
Your choice: (current value [0]) 
    The MySQL Sandbox,  version 3.0.04
    (C) 2006,2007,2008,2009 Giuseppe Maxia
installing with the following parameters:
upper_directory                = /Users/hiroaki/sandboxes
sandbox_directory              = msb_5_1_36
sandbox_port                   = 5136
check_port                     = 0
no_check_port                  = 0
datadir_from                   = script
install_version                = 5.1
basedir                        = /Users/hiroaki/opt/mysql/5.1.36
my_file                        = 
operating_system_user          = hiroaki
db_user                        = msandbox
db_password                    = msandbox
my_clause                      = log-error=msandbox.err
prompt_prefix                  = mysql
prompt_body                    =  [\h] {\u} (\d) > '
force                          = 0
no_ver_after_name              = 1
verbose                        = 0
load_grants                    = 1
no_load_grants                 = 0
no_show                        = 0
do you agree? ([Y],n) 

これでMySQL SandboxとMySQLのインストールは完了だ。なお、レプリケーションや複数インストールはmake_sandboxの代わりに対応するコマンドを実行する。

make_replication実行例

$ make_replication_sandbox $HOME/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz

make_multiple_sandbox実行例。オプションを指定しない場合、3ノードが生成される

$ make_multiple_sandbox $HOME/opt/mysql/mysql-5.1.36-osx10.5-x86.tar.gz