has mysql grown up?

42
Has MySQL Grown Up? Mark Stanton grude

Upload: mark-stanton

Post on 17-May-2015

2.542 views

Category:

Technology


3 download

DESCRIPTION

Much has changed in the MySQL world over the past few years with it being first bought by Sun and then gobbled by Oracle. So is it going to be sucked of oxygen or are Oracle serious about keeping MySQL popular and open?The good news is that despite going quiet for a long while (one releases in 4+ years) it looks like Oracle have shown some love and rolled out significant changes and welcome improvements that improve the MySQL's overall maturity and performance.This talk will walk through practical examples that demonstrate how these features can be best used.Topics include:With InnoDB being chosen over MyISAM as the default storage engine we'll explore the pros & cons of these and other table types.A key to high availability is redundancy, so replication is vital. This talk will walk through real-world examples ranging from simple master-slave setups to more complex multi-master and multi-slave configurations.Now that you have multiple servers up & running the next logical step is a look at the load balancing and failover features built into the latest JDBC drivers.To round things out we'll examine options for backing up your mysql data and check out some of the new monitoring tools Oracle are providing as enterprise (i.e. non-free) add-ons.

TRANSCRIPT

Page 1: Has MySQL grown up?

Has MySQL Grown Up?

Mark Stanton grude

Page 2: Has MySQL grown up?

A brief history

Page 3: Has MySQL grown up?

A brief history1995 Named after Monty’s daughter (My)

2000 Open sourced

2001 3.23

2003 4.0

2005 5.0 Oracle buys the company behind InnoDB

2006 MySQL hits 33% market share, Oracle tries to buy

2008 5.1 Sun acquires MySQL for $1 billion, Monty leaves

2010 5.5 Oracle buys Sun for $7.4 billion

Page 4: Has MySQL grown up?

Where are we now?

• MySQL is growing up

• Oracle are showing love

• Facebook, Google & others are contributing

• Make sure you are running:

• 5.5

• recent version of 5.1

Page 5: Has MySQL grown up?

The wonderful world of Storage Engines

Page 6: Has MySQL grown up?

Storage Engines

• Storage engines are pluggable table types

• You can have multiple storage engines within each a DB

• Transparent to clients (mostly)MyISAM

InnoDB

Page 7: Has MySQL grown up?

MyISAM

• Simple, light weight

• File based

• FULLTEXT indexes

• Table level locking

Page 8: Has MySQL grown up?

InnoDB

• Hot backup

• Active development

• Optimised for multi-core

• Default from 5.5 on

• No FULLTEXT (until 5.6)

• ACID compliant

• Crash safe

• Foreign keys

• Row-level locking

• Table compression

Page 9: Has MySQL grown up?

NDB - MySQL Cluster

• High Availability

• Tables clustered across nodes

• Auto fail & recover

• Auto partitioning

• No FK, limited transactions

• Poor multi-table joins

• Pretends to be MySQL, really whole other product

Page 10: Has MySQL grown up?

Other Storage Engines

• MERGE

• MEMORY

• BLACKHOLE

• CSV (CREATE TABLE export ENGINE=CSV SELECT foo, bar FROM table)

Page 11: Has MySQL grown up?

Storage Engines:Conclusion

• InnoDB is the new default & new direction

• MyISAM is the past

• If you are still on MyISAM, think of moving

• NDB is very interesting for special cases

Page 12: Has MySQL grown up?

Replication

Page 13: Has MySQL grown up?

Why Replicate?

• Scale out

• High availability

• Geographic

• Backup

• Analytics / Business Intelligence

Page 14: Has MySQL grown up?

Under the Hood:Logs

Step 1

Step 2 Step 3

Step 4

IO Thread

SQL Thread

Page 15: Has MySQL grown up?

Under the Hood:Format

• Statement: UPDATE table..

• Records 1100101100111

Page 16: Has MySQL grown up?

Under the Hood:Semi-sync

Step 1

Step 1 Step 1

Step 2

Page 17: Has MySQL grown up?

Configuration: Master-Slave

• Master my.cnf:server-id = 10log-bin=mysql-M1-bin

• Master DB:mysql> CREATE USER 'repl';mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl';

• Slave my.cnf:server-id = 11

• Slave DB:mysql> CHANGE MASTER TO MASTER_HOST='localhost', MASTER_PORT=3310, MASTER_USER='repl';

Name Server-Id Port

M1 10 3310

M1-S1 11 3311

Page 18: Has MySQL grown up?

SHOW SLAVE STATUSmysql> show slave status \G*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Server_Id: 10 Master_Host: localhost Master_Port: 3310 Master_User: repl Master_Log_File: mysql-M1-bin.000017 Read_Master_Log_Pos: 107 Exec_Master_Log_Pos: 107 Slave_IO_Running: Yes Slave_SQL_Running: Yes Last_Errno: 0 Last_Error: Seconds_Behind_Master: 0 Master_Server_Id: 10

Page 19: Has MySQL grown up?

In Practice

Page 20: Has MySQL grown up?

Multi-Master

M1

M1#S1

M2

M2#S1

Page 21: Has MySQL grown up?

Why Multi-Master?

• Active/Passive sites

• High Availability

• Geographically dispersed writes

Page 22: Has MySQL grown up?

Multi-Master: Considerations

Multi-Master replication needs at least one of:

• Conflict Avoidance

• Conflict Resolution

• Hope

Page 23: Has MySQL grown up?

Multi-Master: Considerations

• Conflict Avoidance

• UUIDs

• Auto increment hacksauto_increment_increment = 2auto_increment_offset = 1

• Semi-sync

• Active/Passive

• Ticket server

Page 24: Has MySQL grown up?

Multi-Master: Considerations

• Conflict Resolution

• Cluster/NDB

• Galera

• or roll your own...

Page 25: Has MySQL grown up?

Configuration: Multi-Master

• M2 as slave of M1

• M1 as slave of M2

• M2-S1 as slave of M2

Name Server-Id Port

M1 10 3310

M1-S1 11 3311

M2 20 3320

M2-S1 21 3321 M1

M1#S1

M2

M2#S1

Page 26: Has MySQL grown up?

Review of Topologies

Master

Slave

Master

Slave

Slave

Mul$%Slaves

Master Master Master

Mul)*Slaves

Mul)*Slaves

Master

Slave

Master

Slave

Master Master

Page 27: Has MySQL grown up?

Connector/J

• MySQL’s Connector/J supports:

• Failover

• Load Balancing

• (Replication)

Page 28: Has MySQL grown up?

JDBC Connection Syntax

jdbc:mysql://hostname:port/dbname?property=value

jdbc:mysql://localhost:3306/test?username=root

Page 29: Has MySQL grown up?

JDBC Failover

jdbc:mysql://host1:port1,host2:port2/dbname

Page 30: Has MySQL grown up?

JDBC Load Balancing

jdbc:mysql:loadbalance://host1:port1,host2:port2,host3:port3/dbname

Page 31: Has MySQL grown up?

Warning

• Failover doesn’t attempt to be transparent

• ColdFusion doesn’t allow you full control

• Check/upgrade your Connector/J version

• Set connectionTimeout, socketTimeout and blacklistTimeout carefully

Page 32: Has MySQL grown up?

MySQL Enterprise Monitor

Page 33: Has MySQL grown up?

MySQL Enterprise Monitor

• Heat maps

• Charts

• Query analyser

• Replication status

• Configurable advisors & email alerts

• Event logs

Page 34: Has MySQL grown up?

MySQL Enterprise Monitor

• Server with agents for each mysqld

• Query analyser can have performance hit

• Non-free

Page 35: Has MySQL grown up?

Backing Up MySQL

• Several approaches:

• Copy DB files

• mysqldump

• binlog

• Backup to slave

• mysqlbackup

Page 36: Has MySQL grown up?

Backup: File copy

• Enable read lock:mysql> LOCK TABLES READ;mysql> FLUSH TABLES;

• Run file copy:$ cp -R ./myDB /mybackups/myDB

• Unlock tables:mysql> UNLOCK TABLES;

Page 37: Has MySQL grown up?

Backup: mysqldump

• Creates an sql script containing commands to recreate database

• Run from command-line:$ mysqldump --single-transaction --all-databases > backup_sunday_1_PM.sql

Page 38: Has MySQL grown up?

Backup: binlog

• The binary log:

• records statements

• can be replayed from arbitrary point

• need to know where to replay from

• Rotate binlog mysql> FLUSH LOGS;

• Then copy relevant files

Page 39: Has MySQL grown up?

Backup: Slave

• Setup dedicated slave for backup purposes

• Shutdown slave

• Run backup

• Restart slave

Page 40: Has MySQL grown up?

Backup: mysqlbackup

• Non-free enterprise backup tool

• Features:

• Hot

• Incremental

• Compressed

• Verification

Page 41: Has MySQL grown up?

Summary of Backup Options

copy DB files mysqldump binlog backup to slave mysqlbackup

Hot/Read-Lock Lock Lock (MyISAM)Hot* (InnoDB) Hot Hot Lock (MyISAM)

Hot (InnoDB)

Incremental No No Yes No Yes

InnoDB Support No Yes Yes Yes Yes

Restore Speed Fast OK ** OK Fast Fast

* use --single-transaction for InnoDB** disable for autocommit/FK checks in InnoDB

Page 42: Has MySQL grown up?

Questions?

• Mark Stanton

• http://blog.gruden.com

[email protected]

• @MarkStanto