Date Tags mysql

Mysql-sandbox is a well established utility to setup MySQL instances for test written by Giuseppe Maxia . It takes care of the little differences between mysql versions. To play with different flavours of mysql, I use it on computers that I have access to. In particular I use it on my macbook laptop and my linux machine . The official site of mysql sandbox is http://mysqlsandbox.net/. The blog of author is http://datacharmer.blogspot.it/ a very recommended reading.

Installing mysql binaries

I install mysql binaries into a specifics directory SANDBOX_BINARY. For linux and mac, I use a path starting with /extra/. I find convenient using an /extra/ for my stuff because it not used by other packages (until now!). Normally /opt/ is used to install some optional packages in linux distribution, and I don't wish to mix my things with other package. I can share it between several s.o.. I can mount /extra/ on a different partition and use this partition with different linux distribution. For mysql I make a directory /extra/mysql_home/bins where I uncompress all mysql binaries.

Fist I setup the /extra/ directories tree:

$ sudo mkdir /extra
$ sudo chown 26fe:staff /extra
$ mkdir -p mysql_home/bins
$ export SANDBOX_BINARY=/extra/mysql_home/bins/
$ cd $SANDBOX_BINARY

I downloaded mysql binaries for the last version of mysql 5.7 and uncompress it:

   $ curl -O http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.12-osx10.11-x86_64.tar.gz
   $ tar xfz mysql-5.7.12-osx10.11-x86_64.tar.gz
   $ ln -s mysql-5.7.12-osx10.11-x86_64 5.7.12
   $ ls -l
   lrwxr-xr-x   1 26fe  staff    28B Apr 16 10:46 5.7.12@ -> mysql-5.7.12-osx10.11-x86_64
   drwxr-xr-x  11 26fe  staff   374B Apr 16 10:46 mysql-5.7.12-osx10.11-x86_64/
   -rw-r--r--   1 26fe  staff   313M Apr 16 10:34 mysql-5.7.12-osx10.11-x86_64.tar.gz

I did the same for the last version of mysql 5.6:
$ curl -O http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.30-osx10.11-x86_64.tar.gz
$ tar xfz mysql-5.6.30-osx10.11-x86_64.tar.gz
$ ln -s mysql-5.6.30-osx10.11-x86_64 5.6.30
$ ls -l
lrwxr-xr-x   1 26fe  staff    28B Apr 16 10:49 5.6.30@ -> mysql-5.6.30-osx10.11-x86_64
lrwxr-xr-x   1 26fe  staff    28B Apr 16 10:46 5.7.12@ -> mysql-5.7.12-osx10.11-x86_64
drwxr-xr-x  15 26fe  staff   510B Apr 16 10:48 mysql-5.6.30-osx10.11-x86_64/
drwxr-xr-x  11 26fe  staff   374B Apr 16 10:46 mysql-5.7.12-osx10.11-x86_64/
-rw-r--r--   1 26fe  staff   313M Apr 16 10:34 mysql-5.7.12-osx10.11-x86_64.tar.gz
-rw-r--r--   1 26fe  staff   168M Apr 16 10:42 mysql-5.6.30-osx10.11-x86_64.tar.gz

Installing mysql sandbox

Before installing mysql sandbox let check the perl version.

$ perl --version
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level

I have decided to install the script into the /extra/opt/perl directory. I put all my stuff under the /extra tree:

$ mkdir -p /extra/opt/perl
$ export EXTRA_PERL=/extra/opt/perl

Download the last mysql sandbox from cpan. At the time of writing the last version is the 3.1.05.

$ curl -O http://www.cpan.org/authors/id/G/GM/GMAX/MySQL-Sandbox-3.1.05.tar.gz
$ tar xfz MySQL-Sandbox-3.1.05.tar.gz

Now we build and install the mysql sandbox.

$ cd MySQL-Sandbox-3.1.05
$ perl Makefile.PL PREFIX=$EXTRA_PERL
Checking if your kit is complete...
Looks good
Writing Makefile for MySQL::Sandbox
Writing MYMETA.yml and MYMETA.json

$ make
cp lib/MySQL/Sandbox.pm blib/lib/MySQL/Sandbox.pm
[...]

$ make install
Installing /extra/opt/perl/lib/perl5/site_perl/MySQL/Sandbox.pm
[...]

To have an overview what mysql-sandbox installed on Mac:

$ cd $EXTRA_PERL
$ tree
.
├── Library
│   └── Perl
│       └── Updates
│           └── 5.18.2
│               └── darwin-thread-multi-2level
│                   └── perllocal.pod
├── bin
│   ├── deploy_to_remote_sandboxes.sh
│   ├── low_level_make_sandbox
│   ├── make_multiple_custom_sandbox
│   ├── make_multiple_sandbox
│   ├── make_replication_sandbox
│   ├── make_sandbox
│   ├── make_sandbox_from_installed
│   ├── make_sandbox_from_source
│   ├── msandbox
│   ├── msb
│   ├── sbtool
│   └── test_sandbox
├── lib
│   └── perl5
│       └── site_perl
│           ├── 5.18.2
│           │   └── darwin-thread-multi-2level
│           │       └── auto
│           │           └── MySQL
│           │               └── Sandbox
│           └── MySQL
│               ├── Sandbox
│               │   ├── Recipes.pm
│               │   └── Scripts.pm
│               └── Sandbox.pm
└── share
    └── man
        └── man3
            ├── MySQL::Sandbox.3pm
            ├── MySQL::Sandbox::Recipes.3pm
            └── MySQL::Sandbox::Scripts.3pm

19 directories, 19 files

Editing bash profile

Next I add the following the following lines into my .bash_profile file:

EXTRA_PERL=/extra/opt/perl
export PATH=$EXTRA_PERL/bin:$PATH
export PERL5LIB=/extra/opt/perl/lib/perl5/site_perl/

export SANDBOX_BINARY=/extra/mysql_home/bins
export SANDBOX_HOME=/extra/mysql_home/sandboxes

Finally try to create some mysql sandboxes

$ which make_sandbox
/extra/opt/perl/bin/make_sandbox

$ make_sandbox
    The MySQL Sandbox,  version 3.1.05
    (C) 2006-2016 Giuseppe Maxia

First try to make a 5.7 sandbox

mbp-26fe:~ 26fe$ make_sandbox 5.7.12
Executing low_level_make_sandbox --basedir=/extra/mysql_home/bins/5.7.12 \
    --sandbox_directory=msb_5_7_12 \
    --install_version=5.7 \
    --sandbox_port=5712 \
    --no_ver_after_name \
    --my_clause=log-error=msandbox.err
    The MySQL Sandbox,  version 3.1.05
    (C) 2006-2016 Giuseppe Maxia
Installing with the following parameters:
upper_directory                = /extra/mysql_home/sandboxes
sandbox_directory              = msb_5_7_12
sandbox_port                   = 5712
check_port                     =
no_check_port                  =
datadir_from                   = script
install_version                = 5.7
basedir                        = /extra/mysql_home/bins/5.7.12
tmpdir                         =
my_file                        =
operating_system_user          = 26fe
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                        =
keep_uuid                      =
history_dir                    =
do you agree? ([Y],n) y
loading grants
. sandbox server started
Your sandbox server was installed in $SANDBOX_HOME/msb_5_7_12

We can connect to the new mysql instance:

$ $SANDBOX_BINARY/bins/5.7.12/bin/mysql -umsandbox -pmsandbox -h127.0.0.1 --port 5712
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

We can repeat the same command make_sandbox 5.6.30 for mysql 5.6

That all!


Comments

comments powered by Disqus