mysql in your laptop

60
MySQL in a box (or in your laptop) 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

Upload: giuseppe-maxia

Post on 07-Nov-2014

752 views

Category:

Technology


1 download

DESCRIPTION

Use multiple MySQL instances in a single host, customizing it on-the-fly

TRANSCRIPT

Page 1: MySQL in your laptop

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

Page 2: MySQL in your laptop

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

Page 3: MySQL in your laptop

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

Page 4: MySQL in your laptop

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

Page 5: MySQL in your laptop

MySQL Sandbox lightning

presentation

5

Page 6: MySQL in your laptop

I used to install a lot of MySQL databases for

testing

MANUALLY

6

Page 7: MySQL in your laptop

Then, I decided to use Perl ...

7

Page 8: MySQL in your laptop

DBA pop quiz

8

Page 9: MySQL in your laptop

HOW MANY KEYSTROKES to install a MySQL server?

11msb 5.6.1212345678901

9

Page 10: MySQL in your laptop

HOW MANY KEYSTROKES to install 3 MySQL servers

in replication?

12msb r5.6.14123456789012

10

Page 11: MySQL in your laptop

HOW LONG does it take

to install a MySQL server?

< 5 secondstime msb 5.1.71

0m3.258s11

Page 12: MySQL in your laptop

HOW LONG does it take

to install 3 MySQL servers in replication?

< 10 secondssb 5.1.710m6.314s

12

Page 13: MySQL in your laptop

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

Page 14: MySQL in your laptop

overview

MySQLserver

MySQLserver

Data DB1

DB2 DB3

Data DB1

DB2 DB3DATA DIRECTORY

PORT

SOCKET

14

Page 15: MySQL in your laptop

overview

MySQLserver

MySQLserver

Data DB1

DB2 DB3

Data DB1

DB2 DB3

SAME DATA

DIRECTORY?

DATA CORRUPTION

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

15

Page 16: MySQL in your laptop

overview

MySQLserver

MySQLserver

SAME PORT or SOCKET?

DOES NOT START

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

33063306

16

Page 17: MySQL in your laptop

The hard way

Read the manual try to figure out what to change Install

17

Page 18: MySQL in your laptop

The easy way

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

# it should work always

MySQL Sandbox

18

Page 19: MySQL in your laptop

The easier way

$ make_sandbox 5.1.54

Prepare once Install many times

# some # preliminary # work

19

Page 20: MySQL in your laptop

The easiest way

$ sb 5.1.54

Prepare once Install many times

# some # preliminary # work

20

Page 21: MySQL in your laptop

MySQL Sandbox

MySQLserver

VERSION

$SANDBOX_HOME/msb_VERSION/dataData DB1

DB2 DB3

VERSION

/tmp/mysql_VERSION.sock

21

Page 22: MySQL in your laptop

MySQL Sandbox

MySQLserver

5.1.54

$SANDBOX_HOME/msb_5_1_54/dataData DB1

DB2 DB3

5154

/tmp/mysql_5154.sock

22

Page 23: MySQL in your laptop

MySQL Sandbox

MySQLserver

5.5.34

$SANDBOX_HOME/msb_5_5_34/dataData DB1

DB2 DB3

5534

/tmp/mysql_5534.sock

23

Page 24: MySQL in your laptop

Single SandboxMySQLserver

customized scripts

startstop

restartstatusclear

send_killuse

24

Page 25: MySQL in your laptop

Multiple SandboxMySQLserver

customized scripts

start_allstop_all

restart_allstatus_allclear_all

send_kill_all

use_all

ms1s2

n1n2n3

25

Page 26: MySQL in your laptop

Where do you get it

•from CPANsudo su -

cpan MySQL::Sandbox

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

26

Page 27: MySQL in your laptop

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

Page 28: MySQL in your laptop

default architecture

$HOME

/sandboxes opt

mysql

$SANDBOX_HOME

$SANDBOX_BINARY

expandedtarballs

installed sandboxes

28

Page 29: MySQL in your laptop

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

Page 30: MySQL in your laptop

30

Page 31: MySQL in your laptop

creating a single sandbox

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

31

Page 32: MySQL in your laptop

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

Page 33: MySQL in your laptop

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

Page 34: MySQL in your laptop

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

Page 35: MySQL in your laptop

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

Page 36: MySQL in your laptop

starting a single sandbox

$ cd $SANDBOX_HOME/msb_X_X_XX$ ./start

36

Page 37: MySQL in your laptop

starting a single sandboxwith temporary options

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

$ ./restart --option=value

$ ./start --key-buffer=20000000

37

Page 38: MySQL in your laptop

creating a sandbox with custom port and directory

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

38

Page 39: MySQL in your laptop

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

Page 40: MySQL in your laptop

create a replication sandbox

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

40

Page 41: MySQL in your laptop

create a circular replication sandbox

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

41

Page 42: MySQL in your laptop

changing port to an existing sandbox

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

42

Page 43: MySQL in your laptop

installing the innodb plugin

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

43

Page 44: MySQL in your laptop

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

Page 45: MySQL in your laptop

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

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

45

Page 46: MySQL in your laptop

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

Page 47: MySQL in your laptop

MySQL Sandbox cookbook

$ perldoc MySQL::Sandbox::Recipes

47

Page 48: MySQL in your laptop

testing MySQL creatively

48

Page 49: MySQL in your laptop

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

Page 50: MySQL in your laptop

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

Page 51: MySQL in your laptop

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

Page 52: MySQL in your laptop

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

Page 53: MySQL in your laptop

customizing sandboxes during installation (1)

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

53

Page 54: MySQL in your laptop

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

Page 55: MySQL in your laptop

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

Page 56: MySQL in your laptop

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

Page 57: MySQL in your laptop

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

Page 58: MySQL in your laptop

DEMO

58

Page 59: MySQL in your laptop

Participate!

59

Page 60: MySQL in your laptop

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