mysql in your laptop
DESCRIPTION
Use multiple MySQL instances in a single host, customizing it on-the-flyTRANSCRIPT
MySQL in a box (or in your laptop)
Giuseppe MaxiaQA 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.
http://mysqlsandbox.net
1
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• Oracle ACE Director
•http://datacharmer.blogspot.com
2
An example from a few days ago
• MySQL 5.7.2 was released during the keynote at MySQL Connect• Announced at 9:25• Downloaded at 9:28• Tested with replication at 9:35• In this laptop
3
Another example from the same day
• MySQL 5.7.2 labs preview were announced • Downloaded source at 10:30• Built at 12:30• Tested with replication at 12:35• In this laptop
4
MySQL Sandbox lightning
presentation
5
I used to install a lot of MySQL databases for
testing
MANUALLY
6
Then, I decided to use Perl ...
7
DBA pop quiz
8
HOW MANY KEYSTROKES to install a MySQL server?
11msb 5.6.1212345678901
9
HOW MANY KEYSTROKES to install 3 MySQL servers
in replication?
12msb r5.6.14123456789012
10
HOW LONG does it take
to install a MySQL server?
< 5 secondstime msb 5.1.71
0m3.258s11
HOW LONG does it take
to install 3 MySQL servers in replication?
< 10 secondssb 5.1.710m6.314s
12
MySQL Sandbox
• 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
http://mysqlsandbox.net
13
overview
MySQLserver
MySQLserver
Data DB1
DB2 DB3
Data DB1
DB2 DB3DATA DIRECTORY
PORT
SOCKET
14
overview
MySQLserver
MySQLserver
Data DB1
DB2 DB3
Data DB1
DB2 DB3
SAME DATA
DIRECTORY?
DATA CORRUPTION
/var/lib/mysql /var/lib/mysql
15
overview
MySQLserver
MySQLserver
SAME PORT or SOCKET?
DOES NOT START
/tmp/mysql.sock /tmp/mysql.sock
33063306
16
The hard way
Read the manual try to figure out what to change Install
17
The easy way
$ make_sandbox \ /path/to/mysql-5.1.54_linux.tar.gz
# it should work always
MySQL Sandbox
18
The easier way
$ make_sandbox 5.1.54
Prepare once Install many times
# some # preliminary # work
19
The easiest way
$ sb 5.1.54
Prepare once Install many times
# some # preliminary # work
20
MySQL Sandbox
MySQLserver
VERSION
$SANDBOX_HOME/msb_VERSION/dataData DB1
DB2 DB3
VERSION
/tmp/mysql_VERSION.sock
21
MySQL Sandbox
MySQLserver
5.1.54
$SANDBOX_HOME/msb_5_1_54/dataData DB1
DB2 DB3
5154
/tmp/mysql_5154.sock
22
MySQL Sandbox
MySQLserver
5.5.34
$SANDBOX_HOME/msb_5_5_34/dataData DB1
DB2 DB3
5534
/tmp/mysql_5534.sock
23
Single SandboxMySQLserver
customized scripts
startstop
restartstatusclear
send_killuse
24
Multiple SandboxMySQLserver
customized scripts
start_allstop_all
restart_allstatus_allclear_all
send_kill_all
use_all
ms1s2
n1n2n3
25
Where do you get it
•from CPANsudo su -
cpan MySQL::Sandbox
•from launchpadhttp://launchpad.net/mysql-sandbox
26
The easy replication way
# some# preparation
MySQL Sandbox
$ make_replication_sandbox \ /path/to/mysql-5.1.70_linux.tar.gz
Prepare once Install many times
$ make_replication_sandbox 5.1.70
27
default architecture
$HOME
/sandboxes opt
mysql
$SANDBOX_HOME
$SANDBOX_BINARY
expandedtarballs
installed sandboxes
28
default architecture
$HOME
/sandboxes opt
mysql
5.0.91
5.5.32
5.6.13
5.7.2
msb_5_0_91
msb_5_1_48
rsandbox_5_1_48
master
node1
node229
30
creating a single sandbox
make_sandbox \ /path/to/mysql-X.X.XX-OS.tar.gz
31
using a single sandbox
# after # make_sandbox \# /path/to/mysql-X.X.XX-OS.tar.gz
$ cd $SANDBOX_HOME/msb_X_X_XX$ ./use
32
creating a single sandboxwith a specific options file
make_sandbox \ /path/to/mysql-X.X.XX-OS.tar.gz \ --my_file=/path/to/my.cnf
33
easily create a sandbox after the first one
$ cd $HOME/opt/mysql$ 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
The long way
# $SANDBOX_BINARY
34
easily create a sandbox after the first one
$ make_sandbox --export_binaries \ path/to/mysql-5.1.34-osx10.5-x86.tar.gz
The short way
35
starting a single sandbox
$ cd $SANDBOX_HOME/msb_X_X_XX$ ./start
36
starting a single sandboxwith temporary options
$ cd $SANDBOX_HOME/msb_X_X_XX$ ./start --option=value
$ ./restart --option=value
$ ./start --key-buffer=20000000
37
creating a sandbox with custom port and directory
$ make_sandbox 5.1.34 -- \ --sandbox_port=7800 \ --sandbox_directory=mickeymouse
38
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
39
create a replication sandbox
$ make_replication_sandbox \ path/to/mysql-5.1.34-osx10.5-x86.tar.gz
40
create a circular replication sandbox
$ make_replication_sandbox \ --circular=4 \ path/to/mysql-5.1.34-osx10.5-x86.tar.gz
41
changing port to an existing sandbox
$ sbtool -o port \ -s /path/to/source/sandbox \ --new_port=XXXX
42
installing the innodb plugin
$ sbtool -o plugin \ --plugin=innodb \ -s /path/to/source/sandbox
43
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
44
creating a stand-alone master$ make_sandbox 5.5.16 -- --master
# Creates a sandbox with binary log and# server-id enabled
45
creating a quick slave~/sandboxes/rsandbox_5_5_16/m -e 'show variables like "port"'+---------------+-------+| Variable_name | Value |+---------------+-------+| port | 19771 |+---------------+-------+
$ make_sandbox 5.5.16 -- \ --slaveof='master_port=19771, master_host="xxxx"'
# adds a slave to an existing master
46
MySQL Sandbox cookbook
$ perldoc MySQL::Sandbox::Recipes
47
testing MySQL creatively
48
Breaking replicationmake_replication_sandbox 5.5.32
cd $HOME/sandboxes/rsandbox_5_5_32
./m -e 'create table t1 (i int not null primary key)' test./s1 -e 'insert into t1 values (1)' test./m -e 'insert into t1 values (1)' test./s1 -e 'show slave status\G' | grep 'Error\|Running' Slave_IO_Running: Yes Slave_SQL_Running: No Last_Error: Error 'Duplicate entry '1' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into t1 values (1)' Last_IO_Error: Last_SQL_Error: Error 'Duplicate entry '1' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into t1 values (1)'
49
Fixing replication./s1 -e 'delete from t1 where i = 1' test./s1 -e 'start slave'./s1 -e 'show slave status\G' | grep 'Error\|Running' Slave_IO_Running: Yes Slave_SQL_Running: Yes Last_Error: Last_IO_Error: Last_SQL_Error:
50
Making a slave lag./s1 -e 'stop slave SQL_THREAD'./s2 -e 'stop slave SQL_THREAD'
./m < heavy_load_commands.sql
# 1 hour later
./s1 -e 'start slave SQL_THREAD'
./s2 -e 'start slave SQL_THREAD'
51
Options for replication nodes--master_options = name Options passed to the master --slave_options = name Options passed to each slave --node_options = name Options passed to each node --one_slave_options = name Options passed to a specific slave with the format "N:options"
52
customizing sandboxes during installation (1)
make_replication_sandbox \ --node_options=--high_performance \ --one_slave_options='1:-c read-only'\ 5.5.32
53
customizing sandboxes during installation (2)
./use_all 'show variables like "%innodb%buffer%"'# master Variable_name Valueinnodb_buffer_pool_size 536870912innodb_log_buffer_size 52428800# server: 1: Variable_name Valueinnodb_buffer_pool_size 536870912innodb_log_buffer_size 52428800# server: 2: Variable_name Valueinnodb_buffer_pool_size 536870912innodb_log_buffer_size 52428800
54
customizing sandboxes during installation (3)
./use_all 'show variables like "%read_only%"'# master Variable_name Valueread_only OFF# server: 1: Variable_name Valueread_only ON# server: 2: Variable_name Valueread_only OFF
55
re-playing binary logs
1. new server 2. latest backup
3. new sandbox
4. copy binlogs
5. make the new servera slave of the sandbox
original server
6. remove sandbox
backup
bin logs
56
Testing MySQL 5.7
make_sandbox \ --add_prefix=exp \ --export_binaries \ mysql-5.7.2-m12-osx10.7-x86_64.tar.gz
# and later
make_sandbox exp5.7.2
57
DEMO
58
Participate!
59
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.
THANKS
http://mysqlsandbox.net
60