testing mysql creatively in a sandbox

65
Testing MySQL creatively in a Sandbox 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. http://mysqlsandbox.net 1 Tuesday, April 17, 12

Upload: giuseppe-maxia

Post on 17-May-2015

669 views

Category:

Technology


0 download

DESCRIPTION

Testing MySQL creatively in a sandbox

TRANSCRIPT

Page 1: Testing mysql creatively in a sandbox

Testing MySQL creatively in a Sandbox

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

1Tuesday, April 17, 12

Page 2: Testing mysql creatively in a sandbox

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

2Tuesday, April 17, 12

Page 3: Testing mysql creatively in a sandbox

MySQL Sandbox lightning

presentation

3Tuesday, April 17, 12

Page 4: Testing mysql creatively in a sandbox

I used to install a lot of MySQL databases for

testing

MANUALLY

4Tuesday, April 17, 12

Page 5: Testing mysql creatively in a sandbox

Then, I decided to use Perl ...

5Tuesday, April 17, 12

Page 6: Testing mysql creatively in a sandbox

DBA pop quiz

6Tuesday, April 17, 12

Page 7: Testing mysql creatively in a sandbox

HOW MANY KEYSTROKES to install a MySQL server?

7Tuesday, April 17, 12

Page 8: Testing mysql creatively in a sandbox

HOW MANY KEYSTROKES to install a MySQL server?

10sb 5.0.831234567890

7Tuesday, April 17, 12

Page 9: Testing mysql creatively in a sandbox

HOW MANY KEYSTROKES to install 3 MySQL servers

in replication?

8Tuesday, April 17, 12

Page 10: Testing mysql creatively in a sandbox

HOW MANY KEYSTROKES to install 3 MySQL servers

in replication?

11sb r5.0.8312345678901

8Tuesday, April 17, 12

Page 11: Testing mysql creatively in a sandbox

HOW LONG does it take

to install a MySQL server?

9Tuesday, April 17, 12

Page 12: Testing mysql creatively in a sandbox

HOW LONG does it take

to install a MySQL server?

< 5 secondstime sb 5.0.83

0m1.518s9Tuesday, April 17, 12

Page 13: Testing mysql creatively in a sandbox

HOW LONG does it take

to install 3 MySQL servers in replication?

10Tuesday, April 17, 12

Page 14: Testing mysql creatively in a sandbox

HOW LONG does it take

to install 3 MySQL servers in replication?

< 10 secondssb 5.0.830m4.515s

10Tuesday, April 17, 12

Page 15: Testing mysql creatively in a sandbox

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

11Tuesday, April 17, 12

Page 16: Testing mysql creatively in a sandbox

overview

MySQLserver

MySQLserver

Data DB1

DB2 DB3

Data DB1

DB2 DB3DATA DIRECTORY

PORT

SOCKET

12Tuesday, April 17, 12

Page 17: Testing mysql creatively in a sandbox

overview

MySQLserver

MySQLserver

Data DB1

DB2 DB3

Data DB1

DB2 DB3

SAME DATA

DIRECTORY?

DATA CORRUPTION

/var/lib/mysql /var/lib/mysql

13Tuesday, April 17, 12

Page 18: Testing mysql creatively in a sandbox

overview

MySQLserver

MySQLserver

SAME PORT or SOCKET?

DOES NOT START

/tmp/mysql.sock /tmp/mysql.sock

33063306

14Tuesday, April 17, 12

Page 19: Testing mysql creatively in a sandbox

The hard way

15Tuesday, April 17, 12

Page 20: Testing mysql creatively in a sandbox

The hard way

Read the manual

15Tuesday, April 17, 12

Page 21: Testing mysql creatively in a sandbox

The hard way

Read the manual try to figure out what to change

15Tuesday, April 17, 12

Page 22: Testing mysql creatively in a sandbox

The hard way

Read the manual try to figure out what to change Install

15Tuesday, April 17, 12

Page 23: Testing mysql creatively in a sandbox

The easy way

$ make_sandbox \ /path/to/mysql-5.1.54_linux.tar.gz

# it should work always

MySQL Sandbox

16Tuesday, April 17, 12

Page 24: Testing mysql creatively in a sandbox

The easier way

$ make_sandbox 5.1.54

Prepare once Install many times

# some # preliminary # work

17Tuesday, April 17, 12

Page 25: Testing mysql creatively in a sandbox

The easiest way

$ sb 5.1.54

Prepare once Install many times

# some # preliminary # work

18Tuesday, April 17, 12

Page 26: Testing mysql creatively in a sandbox

MySQL Sandbox

MySQLserver

VERSION

$SANDBOX_HOME/msb_VERSION/dataData DB1

DB2 DB3

VERSION

/tmp/mysql_VERSION.sock

19Tuesday, April 17, 12

Page 27: Testing mysql creatively in a sandbox

MySQL Sandbox

MySQLserver

5.1.54

$SANDBOX_HOME/msb_5_1_54/dataData DB1

DB2 DB3

5154

/tmp/mysql_5154.sock

20Tuesday, April 17, 12

Page 28: Testing mysql creatively in a sandbox

MySQL Sandbox

MySQLserver

5.5.9

$SANDBOX_HOME/msb_5_5_09/dataData DB1

DB2 DB3

5509

/tmp/mysql_5509.sock

21Tuesday, April 17, 12

Page 29: Testing mysql creatively in a sandbox

Single SandboxMySQLserver

customized scripts

startstop

restartstatusclear

send_killuse

22Tuesday, April 17, 12

Page 30: Testing mysql creatively in a sandbox

Multiple SandboxMySQLserver

customized scripts

start_allstop_all

restart_allstatus_allclear_all

send_kill_all

use_all

ms1s2

n1n2n3

23Tuesday, April 17, 12

Page 31: Testing mysql creatively in a sandbox

Where do you get it

•from CPANsudo su -

cpan MySQL::Sandbox

•from launchpadhttp://launchpad.net/mysql-sandbox

24Tuesday, April 17, 12

Page 32: Testing mysql creatively in a sandbox

The easy replication way

# some# preparation

MySQL Sandbox

$ make_replication_sandbox \ /path/to/mysql-5.1.54_linux.tar.gz

Prepare once Install many times

$ make_replication_sandbox 5.1.54

25Tuesday, April 17, 12

Page 33: Testing mysql creatively in a sandbox

default architecture

$HOME

/sandboxes opt

mysql

$SANDBOX_HOME

$SANDBOX_BINARY

expandedtarballs

installed sandboxes

26Tuesday, April 17, 12

Page 34: Testing mysql creatively in a sandbox

default architecture

$HOME

/sandboxes opt

mysql

5.0.91

5.1.45

5.1.48

5.5.4

msb_5_0_91

msb_5_1_48

rsandbox_5_1_48

master

node1

node227Tuesday, April 17, 12

Page 35: Testing mysql creatively in a sandbox

28Tuesday, April 17, 12

Page 36: Testing mysql creatively in a sandbox

creating a single sandbox

make_sandbox \ /path/to/mysql-X.X.XX-OS.tar.gz

29Tuesday, April 17, 12

Page 37: Testing mysql creatively in a sandbox

using a single sandbox

# after # make_sandbox \# /path/to/mysql-X.X.XX-OS.tar.gz

$ cd $SANDBOX_HOME/msb_X_X_XX$ ./use

30Tuesday, April 17, 12

Page 38: Testing mysql creatively in a sandbox

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

31Tuesday, April 17, 12

Page 39: Testing mysql creatively in a sandbox

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

32Tuesday, April 17, 12

Page 40: Testing mysql creatively in a sandbox

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

33Tuesday, April 17, 12

Page 41: Testing mysql creatively in a sandbox

starting a single sandbox

$ cd $SANDBOX_HOME/msb_X_X_XX$ ./start

34Tuesday, April 17, 12

Page 42: Testing mysql creatively in a sandbox

starting a single sandboxwith temporary options

$ cd $SANDBOX_HOME/msb_X_X_XX$ ./start --option=value

$ ./restart --option=value

$ ./start --key-buffer=20000000

35Tuesday, April 17, 12

Page 43: Testing mysql creatively in a sandbox

creating a sandbox with custom port and directory

$ make_sandbox 5.1.34 -- \ --sandbox_port=7800 \ --sandbox_directory=mickeymouse

36Tuesday, April 17, 12

Page 44: Testing mysql creatively in a sandbox

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

37Tuesday, April 17, 12

Page 45: Testing mysql creatively in a sandbox

create a replication sandbox

$ make_replication_sandbox \ path/to/mysql-5.1.34-osx10.5-x86.tar.gz

38Tuesday, April 17, 12

Page 46: Testing mysql creatively in a sandbox

create a circular replication sandbox

$ make_replication_sandbox \ --circular=4 \ path/to/mysql-5.1.34-osx10.5-x86.tar.gz

39Tuesday, April 17, 12

Page 47: Testing mysql creatively in a sandbox

changing port to an existing sandbox

$ sbtool -o port \ -s /path/to/source/sandbox \ --new_port=XXXX

40Tuesday, April 17, 12

Page 48: Testing mysql creatively in a sandbox

installing the innodb plugin

$ sbtool -o plugin \ --plugin=innodb \ -s /path/to/source/sandbox

41Tuesday, April 17, 12

Page 49: Testing mysql creatively in a sandbox

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

42Tuesday, April 17, 12

Page 50: Testing mysql creatively in a sandbox

creating a stand-alone master$ make_sandbox 5.5.16 -- --master

# Creates a sandbox with binary log and# server-id enabled

43Tuesday, April 17, 12

Page 51: Testing mysql creatively in a sandbox

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'

# adds a slave to an existing master

44Tuesday, April 17, 12

Page 52: Testing mysql creatively in a sandbox

MySQL Sandbox cookbook

$ perldoc MySQL::Sandbox::Recipes

45Tuesday, April 17, 12

Page 53: Testing mysql creatively in a sandbox

testing MySQL creatively

46Tuesday, April 17, 12

Page 54: Testing mysql creatively in a sandbox

Breaking replicationmake_replication_sandbox 5.5.16

cd $HOME/sandboxes/rsandbox_5_5_16

./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)'

47Tuesday, April 17, 12

Page 55: Testing mysql creatively in a sandbox

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:

48Tuesday, April 17, 12

Page 56: Testing mysql creatively in a sandbox

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'

49Tuesday, April 17, 12

Page 57: Testing mysql creatively in a sandbox

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"

50Tuesday, April 17, 12

Page 58: Testing mysql creatively in a sandbox

customizing sandboxes during installation (1)

make_replication_sandbox \ --node_options=--high_performance \ --one_slave_options='1:-c read-only'\ 5.1.57

51Tuesday, April 17, 12

Page 59: Testing mysql creatively in a sandbox

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

52Tuesday, April 17, 12

Page 60: Testing mysql creatively in a sandbox

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

53Tuesday, April 17, 12

Page 61: Testing mysql creatively in a sandbox

re-playing binary logs

•1) server become unusable for human error

• 2) install a new server

• 3) load the latest backup

•4) create a sandbox and copy the binary logs to its data directory

• 5) make the new server a slave of the sandbox

•6) wait for completion

•7) reset slave

• 8) remove the sandbox

54Tuesday, April 17, 12

Page 62: Testing mysql creatively in a sandbox

Testing Percona Server

make_sandbox \ --add_prefix=ps \ --export_binaries \ Percona-Server-5.5.21-osx10.7-.tar.gz

# and later

make_sandbox ps5.5.21

55Tuesday, April 17, 12

Page 63: Testing mysql creatively in a sandbox

DEMO

56Tuesday, April 17, 12

Page 64: Testing mysql creatively in a sandbox

Participate!

57Tuesday, April 17, 12

Page 65: Testing mysql creatively in a sandbox

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

58Tuesday, April 17, 12