Presentation on MySQL Sandbox at Percona Live, London 2011
How to install several MySQL servers in the same host, either stand-alone or in groups, easily and painlessly
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
MySQL Sandbox - A toolkit for productive laziness
1. MySQL Sandbox
A toolkit for
productive laziness
Giuseppe Maxia
QA Director, Continuent, Inc
This work is licensed under the Creative Commons
Attribution-Share Alike 3.0 Unported License. To view a
copy of this license, visit http://creativecommons.org/
licenses/by-sa/3.0/ or send a letter to Creative Commons,
171 Second Street, Suite 300, San Francisco, California,
94105, USA.
Tuesday, October 25, 11
2. about me - Giuseppe Maxia
• a.k.a. The Data Charmer
• QA Director at Continuent, Inc
• Long time hacking with MySQL features
• Formerly, community manager,db consultant, designer,
coder.
• A passion for QA and open source
• Blogger
• http://datacharmer.blogspot.com
Tuesday, October 25, 11
3. Laziness
Laziness is a disinclination to
activity or exertion despite
having the ability to do so.
http://en.wikipedia.org/wiki/Laziness
Tuesday, October 25, 11
4. I am an experienced DBA
Tuesday, October 25, 11
5. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
Tuesday, October 25, 11
6. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
Tuesday, October 25, 11
7. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
• Without conflicting.
Tuesday, October 25, 11
8. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
• Without conflicting.
• Manually.
Tuesday, October 25, 11
9. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
• Without conflicting.
• Manually.
• Do I feel inclined to do so?
Tuesday, October 25, 11
10. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
• Without conflicting.
• Manually.
• Do I feel inclined to do so?
• Several times a day?
Tuesday, October 25, 11
11. I am an experienced DBA
• I have the ability of installing
multiple MySQL servers.
• In the same host.
• Without conflicting.
• Manually.
• Do I feel inclined to do so?
• Several times a day?
• I DON'T THINK SO.
Tuesday, October 25, 11
12. I am a command line wizard
Tuesday, October 25, 11
13. I am a command line wizard
• After installing multiple servers
Tuesday, October 25, 11
14. I am a command line wizard
• After installing multiple servers
• I can use them
Tuesday, October 25, 11
15. I am a command line wizard
• After installing multiple servers
• I can use them
• with various long options.
Tuesday, October 25, 11
16. I am a command line wizard
• After installing multiple servers
• I can use them
• with various long options.
• Manually.
Tuesday, October 25, 11
17. I am a command line wizard
• After installing multiple servers
• I can use them
• with various long options.
• Manually.
• Do I feel inclined to do so?
Tuesday, October 25, 11
18. I am a command line wizard
• After installing multiple servers
• I can use them
• with various long options.
• Manually.
• Do I feel inclined to do so?
• Many dozen times a day?
Tuesday, October 25, 11
19. I am a command line wizard
• After installing multiple servers
• I can use them
• with various long options.
• Manually.
• Do I feel inclined to do so?
• Many dozen times a day?
• I DEFINITELY DON'T THINK SO.
Tuesday, October 25, 11
20. I can set up replication
Tuesday, October 25, 11
21. I can set up replication
• Almost without errors.
Tuesday, October 25, 11
22. I can set up replication
• Almost without errors.
• And then I can connect to masters
and slaves with long options on the
command line.
Tuesday, October 25, 11
23. I can set up replication
• Almost without errors.
• And then I can connect to masters
and slaves with long options on the
command line.
• Do I feel inclined to do so?
Tuesday, October 25, 11
24. I can set up replication
• Almost without errors.
• And then I can connect to masters
and slaves with long options on the
command line.
• Do I feel inclined to do so?
• I DON'T THINK SO.
Tuesday, October 25, 11
26. I have the ability
• but I don't feel inclined to do repetitive
work
Tuesday, October 25, 11
27. I have the ability
• but I don't feel inclined to do repetitive
work
• I ADMIT IT: I AM LAZY
Tuesday, October 25, 11
28. I have the ability
• but I don't feel inclined to do repetitive
work
• I ADMIT IT: I AM LAZY
Tuesday, October 25, 11
29. A lazy developer ®
Someone who writes 12,000
lines of code to spare himself
the trouble of typing 15 lines
on a terminal.
Tuesday, October 25, 11
30. A lazy developer ®
Someone who writes 12,000
lines of code to spare himself (*)
the trouble of typing 15 lines
on a terminal.
(*) And another 1,000,000 people
Tuesday, October 25, 11
32. MySQL Sandbox
http://mysqlsandbox.net
• Free software (Perl under GPL)
• One (unix) host
• Many database servers
• Single or multiple sandboxes
• Customized scripts to use the servers
• Standard or circular replication
• Installs IN SECONDS
Tuesday, October 25, 11
33. overview
MySQL MySQL
server server
Data DB1 Data DB1
DB2 DB3
DATA DIRECTORY DB2 DB3
PORT
SOCKET
Tuesday, October 25, 11
34. overview
MySQL MySQL
server server
Data DB1
SAME Data DB1
DB2 DB3
DATA DB2 DB3
DIRECTORY?
/var/lib/mysql /var/lib/mysql
DATA CORRUPTION
Tuesday, October 25, 11
35. overview
MySQL MySQL
server server
SAME
PORT or
SOCKET?
3306 3306
/tmp/mysql.sock /tmp/mysql.sock
DOES NOT START
Tuesday, October 25, 11
38. The easy way
$ make_sandbox
/path/to/mysql-5.1.54_linux.tar.gz
$ make_sandbox
Percona-Server-5.1.54_linux.tar.gz
# it should work always
Tuesday, October 25, 11
39. The easier way
$ make_sandbox 5.1.54
# Needs some preliminary work
Tuesday, October 25, 11
40. The easiest way
$ sb 5.1.54
# Needs the same preliminary work
Tuesday, October 25, 11
41. MySQL Sandbox
VERSION
MySQL
server
Data DB1
DB2 DB3
$SANDBOX_HOME/msb_VERSION/data
VERSION
/tmp/mysql_VERSION.sock
Tuesday, October 25, 11
42. MySQL Sandbox
5.1.54
MySQL
server
Data DB1
DB2 DB3
$SANDBOX_HOME/msb_5_1_54/data
5154
/tmp/mysql_5154.sock
Tuesday, October 25, 11
43. MySQL Sandbox
5.5.9
MySQL
server
Data DB1
DB2 DB3
$SANDBOX_HOME/msb_5_5_09/data
5509
/tmp/mysql_5509.sock
Tuesday, October 25, 11
44. Single Sandbox
MySQL customized scripts
server
start
stop
restart
status
clear
send_kill
use
Tuesday, October 25, 11
45. Multiple Sandbox
MySQL customized scripts
server
start_all
stop_all
restart_all m n1
status_all s1 n2
clear_all s2 n3
send_kill_a
ll
use_all
Tuesday, October 25, 11
46. Where do you get it
•from CPAN
sudo cpan MySQL::Sandbox
•from launchpad
http://launchpad.net/mysql-sandbox
Tuesday, October 25, 11
47. The easy replication way
$ make_replication_sandbox
/path/to/mysql-5.1.54_linux.tar.gz
# or, after some preparation
$ make_replication_sandbox 5.1.54
Tuesday, October 25, 11
48. default architecture
$HOME
/sandboxes opt
expanded
tarballs
$SANDBOX_HOME
mysql
$SANDBOX_BINARY
installed
sandboxes
Tuesday, October 25, 11
51. creating a single sandbox
make_sandbox
/path/to/mysql-X.X.XX-OS.tar.gz
Tuesday, October 25, 11
52. using a single sandbox
# after
# make_sandbox
# /path/to/mysql-X.X.XX-OS.tar.gz
$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./use
Tuesday, October 25, 11
53. creating a single sandbox
with a specific options file
make_sandbox
/path/to/mysql-X.X.XX-OS.tar.gz
-- --my_file=/path/to/my.cnf
Tuesday, October 25, 11
54. easily create a sandbox after the first
one
The long way
$ cd $HOME/opt/mysql # $SANDBOX_BINARY
$ gunzip -c
/path/to/mysql-5.1.34-osx10.5-x86.tar.gz
| tar -xf -
$ mv mysql-5.1.34-osx10.5-x86 5.1.34
$ make sandbox 5.1.34
Tuesday, October 25, 11
55. easily create a sandbox after the first
one
The short way
$ make_sandbox --export_binaries
path/to/mysql-5.1.34-osx10.5-x86.tar.gz
Tuesday, October 25, 11
56. starting a single sandbox
$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./start
Tuesday, October 25, 11
57. starting a single sandbox
with temporary options
$ cd $SANDBOX_HOME/msb_X_X_XX
$ ./start --option=value
$ ./restart --option=value
$ ./start --key-buffer=20000000
Tuesday, October 25, 11
58. creating a sandbox with custom port
and directory
$ make_sandbox 5.1.34 --
--sandbox_port=7800
--sandbox_directory=mickeymouse
Tuesday, October 25, 11
59. creating a sandbox with automatic
port checking
$ make_sandbox 5.1.34 -- --check_port
# if 5.1.34 is free
# port=5134
# directory=msb_5_1_34
# else
# port=5135 (or the first free)
# directory=msb_5_1_34_a
Tuesday, October 25, 11
60. create a replication sandbox
$ make_replication_sandbox
path/to/mysql-5.1.34-osx10.5-x86.tar.gz
Tuesday, October 25, 11
61. create a circular replication sandbox
$ make_replication_sandbox
--circular=4
path/to/mysql-5.1.34-osx10.5-x86.tar.gz
Tuesday, October 25, 11
62. changing port to an existing sandbox
$ sbtool -o port
-s /path/to/source/sandbox
--new_port=XXXX
Tuesday, October 25, 11
63. installing the innodb plugin
$ sbtool -o plugin
--plugin=innodb
-s /path/to/source/sandbox
Tuesday, October 25, 11
64. creating a replication sandbox with
new base port
$ make_replication_sandbox
--replication_directory=newwdir
--check_base_port 5.0.79
# Creates a replication directory under
# $SANDBOX_HOME/newdir
# The previous one is preserved.
# No conflicts happen
Tuesday, October 25, 11
65. more recipes
$ perldoc MySQL::Sandbox::Recipes
Tuesday, October 25, 11
69. tungsten sandbox help
./tools/tungsten-sandbox -h
USAGE: ./tools/tungsten-sandbox [flags] args
flags:
-n,--nodes: how many nodes to install (default: 3)
-m,--mysql_version: which MySQL version to use (default: '5.5.13')
-t,--tungsten_base: where to install the sandbox (default: '$HOME/tsb2/')
-d,--group_dir: sandbox group directory name (default: 'tr_dbs')
-x,--tsb_prefix: Tungsten Sandbox prefix (default: 'db')
-s,--service: how the service is named (default: 'tsandbox')
-P,--base_port: port base for MySQL sandbox nodes (default: 7100)
-l,--thl_port: port for the THL service (default: 12110)
-r,--rmi_port: port for the RMI service (default: 10100)
-v,--[no]version: show Tungsten sandbox version (default: false)
-h,--[no]help: show Tungsten sandbox help (default: false)
Tuesday, October 25, 11
70. tungsten sandbox
$ ./tools/tungsten-sandbox -m 5.5.10
executing "clear" on node 1
executing "clear" on node 2
executing "clear" on node 3
installing node 1
installing node 2
installing node 3
group directory installed in $HOME/sandboxes/tr_dbs
Tuesday, October 25, 11
74. THANKS
Let's talk!
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. To view a copy of this license, visit http://
creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California,
94105, USA.
Tuesday, October 25, 11