SlideShare a Scribd company logo
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
Installation, Configuration
and performance tuning
Mark Swarbrick
Principle Presales Consultant
MySQL Webinar Series 2/4
Program
Agenda
Â§ï‚§â€Ż Hardware Specification
Â§ï‚§â€Ż Setting up Replication
Â§ï‚§â€Ż Performance tuning
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
The following is intended to outline our general product direction. It is
intended for information purposes only, and may not be incorporated
into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing
decision. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole
discretion of Oracle.
Safe Harbor Statement
Â§ï‚§â€Ż Hardware Specification
MySQL Hardware / Software Platforms
MySQL is supported on a variety of hardware /
software platforms:
Oracle Linux
Oracle Solaris
Red Hat
Canonical (Ubuntu)
SUSE
Debian
Microsoft Windows XP/Vista/7/2003/2008/2012/server
FreeBSD
HPUX
Other Linux – Fedora / OpenSUSE / CentOS etc
MySQL Hardware / Software Platforms
MySQL is supported on a variety of hardware /
software platforms:
X86
X86_64
X86_IA64
SPARC_32
SPARC_64
IBM Power5_64
PA-RISC 2.0
We will support with best efforts on other hardware platforms such
as ARM. For example MySQL Cluster compiled to run on a
raspberry pi!
Copyright Oracle Corporation 2014 | <date>8
Scaling on dense,
multi-core, multi-thread
servers
‱  10s - 100GBs RAM
‱  SSDs
Scale across cores
within a single instance
You can get a long
way with MySQL 5.6!
The Path to Scalability
Scaling-Up can take you a long way
MySQL Hardware / Software Platforms
Server:
Having the fastest CPU is still beneficial. Can use as many as 32 cores!
OS choice and tuning is important, but Linux / Solaris or windows all give good
performance.
Storage:
Don’t use slow disks
Flash memory (SSD etc) helps for random access (reads are the most costly)
FS is important – ZFS, UFS, QFS, VxFS, EXT3, EXT4 XFS etc..
Use of O_Direct if O/S supports it
Don’t forget the network! Faster is better!
Hardware: The Perfect MySQL Server
‱  The more cores the better (especially for 5.5 and later)
‱  x86_64 - 64 bit for more memory is important
–  The more the better
‱  Fast HD (10-15k RPM SATA) or NAS/SAN


–  RAID 10 for most, RAID 5 OK if very read intensive
–  Hardware RAID battery backed up cache critical!
–  More disks are always better! - 4+ recommended, 8-16 can increase IO
‱  
Or SSD (for higher throughput)
–  Intel, Fusion-IO good choices; good option for Slaves
‱  At least 2 x NICs for redundancy
‱  Slaves should be as powerful as the Master
Â§ï‚§â€Ż Replication
MySQL HA Solutions
Note that MySQL Fabric is currently at Release Candidate Status
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13
Why Replicate?
Â§ï‚§â€Ż Duplicates database from a “master” to a “slave”
Â§ï‚§â€Ż Redundant copies of the data provide foundation for High Availability
Â§ï‚§â€Ż Scale out by distributing queries across the replication cluster
Master
Slaves
Web / App Servers
Writes & Reads Reads
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14
Slave
Database
Â§ï‚§â€Ż Session thread: processes queries from
the application – writes data to master
database & associated events to binary
log
Â§ï‚§â€Ż Dump thread: reads events from binary
log and sends them to a slave
Â§ï‚§â€Ż I/O thread: receives replication events
and stores them in slave’s relay log
Â§ï‚§â€Ż SQL thread: reads replication events from
slave’s relay log and applies them to
slave database
Session
Binary
Log
Master
Database
Dump I/O
Relay
Log
SQL
Replication Workflow
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15
ReplicationReplication Solutions
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16
Async Replication
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17
Semi-sync Replication
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18
MySQL 5.6: Transforming Replication
‱  Multi-Threaded Slaves
‱  Binary Log Group Commit
‱  Optimized Row-Based Replication
PERFORMANCE
‱  Global Transaction Identifiers
‱  Replication Failover & Admin Utilities
‱  Crash Safe Slaves & Binlogs
FAILOVER & RECOVERY
‱  Replication Event Checksums
DATA INTEGRITY
‱  Replication Utilities
‱  Time-Delayed Replication
‱  Remote Binlog Backup
‱  Informational Log Events
‱  Server UUIDs
DEV/OPS AGILITY
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19
5x Higher Performance with MySQL 5.6
0 5 10
QPS 58.11 144.4 282.53
0
50
100
150
200
250
300
QueriesperSecond
Worker Threads
Multi-Threaded Slave Performance
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20
Master
GTID=123456
GTID=123456
GTID=123456 GTID=123456
Global Transaction Identifiers
Â§ï‚§â€Ż Simple to track & compare replication across the farm
Â§ï‚§â€Ż Unique identifier for each transaction written to the Binlog
Â§ï‚§â€Ż Automatically identify the most up-to-date slave for failover
Â§ï‚§â€Ż Deploy n-tier replication hierarchies
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21
Time Delayed Replication - configuring
slave2> CHANGE MASTER TO
-> MASTER_HOST = 'localhost‘,
-> MASTER_PORT = 3306,
-> MASTER_USER = 'repl_user‘,
-> MASTER_PASSWORD = ‘sun123!‘,
-> MASTER_DELAY = 600;
slave2> START SLAVE;
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22
MySQL Utilities
Â§ï‚§â€Ż Automate common Dev/Ops tasks
Â§ï‚§â€Ż Replication: provisioning, testing, monitoring and failover
Â§ï‚§â€Ż Database comparisons: consistency checking
Â§ï‚§â€Ż Database administration: users, connections, tables, etc
Â§ï‚§â€Ż New utilities in development, i.e. log analysis
Â§ï‚§â€Ż Implemented as Python scripts, plug-in for MySQL Workbench
Â§ï‚§â€Ż Extensible to include custom scripting
Â§ï‚§â€Ż Resources: Documentation & Community Forum
Â§ï‚§â€Ż http://dev.mysql.com/doc/workbench/en/mysql-utils-man.html
Â§ï‚§â€Ż http://forums.mysql.com/list.php?155
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23
Utility Workflow for Replication
Â§ï‚§â€Ż Replicate: Initiates Replication to the new slave
Â§ï‚§â€Ż Check: Validates the replication configuration and operation
Â§ï‚§â€Ż Show: Display Replication topology
Â§ï‚§â€Ż Fail-Over & Admin: Detects and failovers (or switches) from master to
slave. Status monitoring
Check Show
Fail-Over
& AdminReplicate
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24
mysqlreplicate Utility
Â§ï‚§â€Ż Starts replication process
Â§ï‚§â€Ż User can provide login and
connection parameters for the master
Â§ï‚§â€Ż Configurable replication start points:
current position / GTID, specific
event, entire binlog
Â§ï‚§â€Ż Checks storage engine compatibility
Â§ï‚§â€Ż Enables fast, simple scaling
New Slave
Login,
Connection &
Start-Point
Master
Replication configured,
binlog position
Repl
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25
mysqlreplicate example
$ mysqlreplicate --master=root:billy@localhost:3306
--slave=root:billy@localhost:3307
# master on localhost: ... connected.
# slave on localhost: ... connected.
Repl
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26
mysqlrplshow Utility
Â§ï‚§â€Ż Discovers & displays replication
topology
Â§ï‚§â€Ż Shows slaves attached to each
master
Â§ï‚§â€Ż Labels each slave with hostname
and port number
Â§ï‚§â€Ż Displays multiple topologies,
including hierarchical and circular
Â§ï‚§â€Ż Displays results in a graph or list
Â§ï‚§â€Ż Enables user to monitor topology
on-demand
$ mysqlrplshow --master=root@localhost:3311
# master on localhost: ... connected.
# Finding slaves for master: localhost:3311
# Replication Topology Graph::
localhost:3306 (MASTER)
|
+--- localhost:3307 - (SLAVE)
|
+--- localhost:3308 - (SLAVE + MASTER)
|
+--- localhost:3313 - (SLAVE)
Show
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27
mysqlrplcheck Utility
Â§ï‚§â€Ż Tests replication on master and slave to ensure proper configuration of
replication
Â§ï‚§â€Ż Checks binlog is enabled and displays any configured exceptions
Â§ï‚§â€Ż Checks slave access and privileges to master
Â§ï‚§â€Ż Checks slave connection status
Â§ï‚§â€Ż Checks for conflicts in master.info file (or mysql.slave_master_info table)
Â§ï‚§â€Ż Checks storage engine compatibility
Â§ï‚§â€Ż Tests executed sequentially
Â§ï‚§â€Ż Reports status of each test
Â§ï‚§â€Ż Simple verification of deployment & fast fault resolution
Check
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28
mysqlrplcheck example
$ mysqlrplcheck --master=root@host1:3310
--slave=root@host2:3311
# master on host1: ... connected.
# slave on host2: ... connected. Test Description Status
-------------------------------------------------------------
Checking for binary logging on master [pass]
Are there binlog exceptions? [pass]
Replication user exists? [pass]
Checking server_id values [pass]
Is slave connected to master? [pass]
Check master information file [pass]
Checking InnoDB compatibility [pass]
Checking storage engines compatibility [pass]
Checking lower_case_table_names settings [pass]
Checking slave delay (seconds behind master) [pass]
# ...done.
Check
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29
Replication Administration Utility
Â§ï‚§â€Ż Perform switchover to eliminate
downtime during planned maintenance
Â§ï‚§â€Ż Start and stop slaves
Â§ï‚§â€Ż Slave discovery & monitoring
Â§ï‚§â€Ż Slave status, thread status
Â§ï‚§â€Ż Replication processing, including any lag
Â§ï‚§â€Ż Configure slave promotion policies
Master
Slaves
Administration
Utility
Status &
Switchover
Admin
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30
Planned switchover to new master with
mysqlrpladmin
$ mysqlrpladmin --master=root@rod:3306
--slaves=root@jane:3306,root@jane:3307,root@freddy:3306
--new-master=root@jane:3306 --demote-master switchover
# Performing switchover from master at rod:3306 to slave at jane:3306.
# Checking candidate slave prerequisites.
# Waiting for slaves to catch up to old master.
# Stopping slaves.
# Performing STOP on all slaves.
# Demoting old master to be a slave to the new master.
# Switching slaves to new master.
# Starting all slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Switchover complete.
# ...done.
Switch-
Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31
Â§ï‚§â€Ż Enabling self-healing replication topologies
Â§ï‚§â€Ż Automated failover & recovery
Â§ï‚§â€Ż mysqlfailover Utility
Â§ï‚§â€Ż Switchover & administration
Â§ï‚§â€Ż mysqlrpladmin Utility
Â§ï‚§â€Ż Fully configurable slave promotion policies
Â§ï‚§â€Ż Delivers HA within the core MySQL
distribution
HA UtilitiesMonitoring
Failed
Master
Slaves
Promoted
Master
Fail-Over
& Admin
Replication HA Utilities
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32
mysqlfailover – monitoring resumes
MySQL Replication Monitor and Failover Utility
Failover Mode = auto Next Interval = Mon Mar 19 16:05:12 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000001 1117
GTID Executed Set
A0F7E82D-3554-11E2-9950-080027685B56:1-5
UUIDs
+------------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+------------+-------+---------+--------+------------+---------+
| jane | 3306 | MASTER | UP | ON | OK |
| jane | 3307 | SLAVE | UP | ON | OK |
| freddy | 3306 | SLAVE | UP | ON | OK |
+------------+-------+---------+--------+------------+---------+
Fail-Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33
mysqlfailover – master failed
Failover starting...
# Candidate slave jane:3306 will become the new master.
# Preparing candidate for failover.
# Creating replication user if it does not exist.
# Stopping slaves.
# Performing STOP on all slaves.
# Switching slaves to new master.
# Starting slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Failover complete.
# Discovering slaves for master at jane:3306
Failover console will restart in 5 seconds.
Fail-Over
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34
An extensible and easy-to-
use framework for
managing a farm of MySQL
server supporting high-
availability and sharding
MySQL Fabric
Copyright Oracle Corporation 2014 | <date>35
MySQL Fabric Framework (HA)
All Data
Primary Secondary
Extra Read
Replicas
MySQL Fabric
Controller
SQL Queries
State &
Routing Info
HA Group
Coordination
and Control
Copyright Oracle Corporation 2014 | <date>36
MySQL Replication & MySQL Fabric HA
Â§ï‚§â€Ż MySQL Replication is the initial implementation used in HA Groups
–  PRIMARY = Replication Master & receives all writes
Â§ï‚§â€Ż Failover
–  MySQL Fabric detects failure of PRIMARY/Master
–  Selects a SECONDARY/Slave and promotes it
–  Updates State Store
–  Updated state fetched by Fabric-aware connectors
& how this effects failover
Copyright Oracle Corporation 2014 | <date>37
High-Availability Group Concept
Â§ï‚§â€Ż Abstract Concept
–  Set of servers
–  Server attributes
Â§ï‚§â€Ż Connector Attributes
–  Connection information
–  Mode: read-only, read-write, ...
–  Weight: distribute load
Â§ï‚§â€Ż Management Attributes
–  State: state/role of the server State: Primary
Mode: Read-Write
Host: server-1.example.com
Copyright Oracle Corporation 2014 | <date>38
Create HA Groups and add Servers
Â§ï‚§â€Ż Define a group
mysqlfabric group create my_group
Â§ï‚§â€Ż Add servers to group
mysqlfabric group add my_group server1.example.com
mysqlfabric group add my_group server2.example.com
Copyright Oracle Corporation 2014 | <date>39
Create HA Groups and add Servers
Â§ï‚§â€Ż Promote one server to be primary
mysqlfabric group promote my_group
Â§ï‚§â€Ż Tell failure detector to monitor group
mysqlfabric group activate my_group
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40
Â§ï‚§â€Ż Performance Tuning
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Rules of Tuning‹
	
‱  Never make a change in production first
‱  Have a good benchmark or reliable load
‱  Start with a good baseline
‱  Only change 1 thing at a time
–  identify a set of possible changes
–  try each change separately
–  try in combinations of 2, then 3, etc.
‱  Monitor the results
–  Query performance - query analyzer, slow query log, etc.
‱  throughput
‱  single query time
‱  average query time
–  CPU - top, vmstat, dstat
–  IO - iostat, top, vmstat, bonnie++, dstat
–  Network bandwidth
‱  Document and save the results
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Were do I find a benchmark?
‱  Make your own
–  Can use general query log output
–  Could use MySQL Proxy and TCP Dump
‱  DBT2
–  http://osdldbt.sourceforge.net/
–  http://samurai-mysql.blogspot.com/2009/03/settingup-dbt-2.html
‱  mysqlslap MySQL 5.1 +
–  http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html
‱  SysBench
–  http://sysbench.sourceforge.net/
‱  supersmack
–  http://vegan.net/tony/supersmack/
‱  mybench
–  http://jeremy.zawodny.com/mysql/mybench/
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
InnoDB Tuning‹
	
‱  Unlike MyISAM - InnoDB uses a single cache for both index and data
–  innodb_buffer_pool_size - should be 70-80% of available
memory.
–  It is not uncommon for this to be very large, i.e. 34GB on a system with
40GB of memory
–  Make sure its not set so large as to cause swapping!
–  mysql>show status like 'Innodb_buffer%' ;
‱  InnoDB can use direct IO on systems that support it - Linux, FreeBSD,
and Solaris
–  innodb_flush_method = O_DIRECT
‱  For more InnoDB tuning see
–  http://dev.mysql.com/doc/refman/5.1/en/innodb-tuning-
troubleshooting.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
DBT-2 (W200) Transactions per Minute %user %iowait
Buffer pool 1G 1125.44 2% 30%
Buffer pool 2G 1863.19 3% 28%
Buffer pool 5G 4385.18 5.5% 33%
Buffer pool 30G
(All data in cache)
36784.76 36% 8%
Cache hot application data in memory‹
	
‱  DBT-2 benchmark (write intensive)
‱  20-25GB hot data (200 warehouses, running 1 hour)
‱  Nehalem 2.93GHz x 8 cores, MySQL 5.5.2, 4 RAID1+0 HDDs
‱  RAM size affects everything. Not only for SELECT, but also for INSERT/UPDATE/DELETE
–  INSERT: Random reads/writes happen when inserting into indexes in random order
–  UPDATE/DELETE: Random reads/writes happen when modifying records
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Connections‹
	
‱  MySQL Caches the threads used by a connection
–  thread_cache_size - Number of threads to cache
–  Setting this to 100 or higher is not unusual
‱  Monitor Threads_created to see if this is an issue
–  Counts connections not using the thread cache
–  Should be less than 1-2 a minute
–  Usually only an issue if more than 1-2 a second
‱  Only an issue if you create and drop a lot of connections, i.e. PHP
‱  Overhead is usually about 250k per thread
‱  Aborted_clients -
http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
‱  Aborted_connections -
http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Sessions‹
	
‱  Some session variables control space allocated by each session (per connection)
–  Setting these to small can give bad performance
–  Setting these too large can cause the server to swap!
–  Can be set by connection
‱  SET SORT_BUFFER_SIZE=1024*1024*128
–  Set small by default, increase in connections that need it
‱  sort_buffer_size - Used for ORDER BY, GROUP
‱  	
 BY, SELECT DISTINCT, UNION DISTINCT
–  Monitor Sort_merge_passes < 1-2 an hour optimal
–  Usually a problem in a reporting or data warehouse database
‱  Other important session variables
–  read_rnd_buffer_size - Set to 1/2 sort_buffer_size
–  join_buffer_size - Watch Select_full_join
–  read_buffer_size - Used for full table scans, watch Select_scan
–  tmp_table_size - Max temp table size in memory, watch Created_tmp_disk_tables
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Query Cache‹
	
‱  MySQL’s ‘Jekyll and Hyde’ of performance tuning options, when it is useful it really
helps, when it hurts, it really hurts
‱  MySQL Query Cache caches both the query and the full result set
–  query_cache_type - Controls behaviour
‱  0 or OFF - Not used (buffer may still be allocated)
‱  1 or ON cache all unless SELECT SQL_NO_CACHE (DEFAULT)
‱  2 or DEMAND cache none unless SELECT SQL_CACHE
–  query_cache_size - Determines the size of the cache
‱  mysql> show status like 'Qc%' ;
‱  Gives great performance if:
–  Identical queries returning identical data are used often
–  No or rare inserts, updates or deletes
‱  Best Practice
–  Set to DEMAND
–  Add SQL_CACHE to appropriate queries
Indexing
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Indexes in MySQL‹
	
‱  Indexes allow for faster access to data
‱  Data accessed via an index is usually in sorted order
‱  Unique or Primary - Must refer to only one record
‱  Non-Unique - May refer to many records
‱  Can be on one or more columns
–  CREATE INDEX IDX ON TAB1(col1,col2,col3) ;
‱  Can use prefix index for
–  CHAR, VARCHAR, BINARY, and VARBINARY
–  CREATE INDEX PRE ON TAB1(COL1(10)) ;
–  Prefix is in bytes, not characters
‱  Very useful for large strings
‱  Works best when leading part of column is selective
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Index Best Practices‹
	
‱  Too many indexes can slow down inserts/deletes
–  Use only the indexes you must have
–  Check often
–  mysql>show create table tabname ;
‱  Don’t duplicate leading parts of compound keys
–  index key123 (col1,col2,col3)
–  index key12 (col1,col2) <- Not needed!
–  index key1 (col1) <-- Not needed!
‱  Use prefix indexes on large keys
‱  Best indexes are 16 bytes/chars or less (> 16 text?)
‱  Indexes bigger than 32 bytes/chars should be looked at very closely
–  should have there own cache if in MyISAM
‱  For large strings that need to be indexed, i.e. URLs, consider using a separate
column using the MySQL MD5 to create a hash key and index on it instead
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and
L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
| 1 | SIMPLE | C | ALL | NULL | NULL | NULL | NULL | 239 | Using where |
| 1 | SIMPLE | Y | ALL | NULL | NULL | NULL | NULL | 4079 | Using where; Using join buffer |
| 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index |
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+
3 rows in set (0.00 sec)
(Using the MySQL World database)
http://dev.mysql.com/doc/index-other.html
Explain ‹
	
‱  Order that the tables are accessed
‱  Indexes used
‱  Estimated number of rows accessed per table
‱  select C.Name, Y.Name, Y.Population, Language from Country
as C, City as Y, CountryLanguage as L where Y.Name = C.Name
and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Explain - Details‹
	
‱  Tables are accessed from top to bottom
‱  Columns
–  Select Type - SELECT if no Union or Subquery
–  Table, uses aliases
–  Type - Most common ref or eq_ref
–  Possible Keys - Indexes the optimizer is considering
–  Key = The index the optimizer chose
–  Ref - What column in what table (using alias) is referenced by the index
–  Rows - Estimated number of rows per reference
‱  Multiple these to get overall cost
‱  There are more values, see:
‱  http://dev.mysql.com/doc/refman/5.6/en/using-explain.html
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
mysql> explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and
L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
|+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
| 1 | SIMPLE | C | ref | c2 | c2 | 52 | const | 1 | Using where; Using index |
| 1 | SIMPLE | Y | ref | c2 | c2 | 35 | const | 1 | Using where |
| 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index
|+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+
3 rows in set (0.00 sec)
More Explain‹
	
‱  alter table Country add index c2 (Name) ;
‱  alter table City add index c2 (Name) ;
‱  The original cost was 239 * 4079 * 9 = 8,773,929
‱  The new cost is 1 * 1 * 9 = 9
Query Tuning Rules
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Queries‹
	
‱  Often the # 1 issue in overall performance
‱  Always, Always have your slow query log on!
–  http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html
–  Use: log_queries_not_using_indexes
–  Check it regularly
–  Use mysqldumpslow : http://dev.mysql.com/doc/refman/5.1/en/mysqldumpslow.html
–  Best practice is to automate running mysqldumpslow every morning and email results
to DBA, DBDev, etc.
‱  Understand and use EXPLAIN
–  http://dev.mysql.com/doc/refman/5.1/en/using-explain.html
‱  Select_scan - Number of full table scans
‱  Select_full_join - Joins without indexes
‱  MySQL Query Analyzer
–  http://www.mysql.com/products/enterprise/query.html
Schema
The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle
Schemas‹
	
‱  Size = performance, smaller is better
–  Size right! Do not automatically use 255 for VARCHAR
‱  Temp tables, most caches, expand to full size
‱  Use “procedure analyse” to determine the optimal types given the values in your
table
–  http://dev.mysql.com/doc/refman/5.1/en/procedure-analyse.html
–  mysql> select * from tab procedure analyse (64,2000) G
‱  Consider the types:
–  enum : http://dev.mysql.com/doc/refman/5.1/en/enum.html
–  set : http://dev.mysql.com/doc/refman/5.1/en/set.html
‱  Compress large strings
–  Use the MySQL COMPRESS and UNCOMPRESS functions
–  Very important in InnoDB 5.5, now with barracuda not so bad
Partitioning can help performance
lïŹâ€Ż Single inserts and selects faster
lïŹâ€Ż Range selects faster
lïŹâ€Ż More efficiently split the data across different paths
lïŹâ€Ż Historical data stored efficiently
lïŹâ€Ż delete large chunks of data (drop partition)
lïŹâ€Ż Move from table to partition easy 5.6
MySQL 5.6 Performance Schema
‱  PERFORMANCE_SCHEMA presents low level
MySQL performance information
‱  Data can be cleared
‱  Filters with WHERE are allowed
‱  Must be enabled with --performance_schema
mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT
-> FROM EVENTS_WAITS_HISTORY WHERE THREAD_ID = 13
-> ORDER BY EVENT_ID;
+----------+-----------------------------------------+------------+
| EVENT_ID | EVENT_NAME | TIMER_WAIT |
+----------+-----------------------------------------+------------+
| 86 | wait/synch/mutex/mysys/THR_LOCK::mutex | 686322 |
| 87 | wait/synch/mutex/mysys/THR_LOCK_malloc | 320535 |
| 88 | wait/synch/mutex/mysys/THR_LOCK_malloc | 339390 |
| 89 | wait/synch/mutex/mysys/THR_LOCK_malloc | 377100 |
| 90 | wait/synch/mutex/sql/LOCK_plugin | 614673 |
| 91 | wait/synch/mutex/sql/LOCK_open | 659925 |
| 92 | wait/synch/mutex/sql/THD::LOCK_thd_data | 494001 |
| 93 | wait/synch/mutex/mysys/THR_LOCK_malloc | 222489 |
| 94 | wait/synch/mutex/mysys/THR_LOCK_malloc | 214947 |
| 95 | wait/synch/mutex/mysys/LOCK_alarm | 312993 |
+----------+-----------------------------------------+------------+
mysql> UPDATE SETUP_INSTRUMENTS
-> SET ENABLED = 'NO'
-> WHERE NAME = 'wait/synch/mutex/myisammrg/MYRG_INFO::mutex';
mysql> UPDATE SETUP_CONSUMERS
-> SET ENABLED = 'NO' WHERE NAME = 'file_summary_by_instance';
© 2010 Oracle Corporation – Proprietary and Confidential
‱  Statements/Stages
‱  What are my most resource intensive queries? Where do they spend time?
‱  Table/Index I/O, Table Locks
‱  Which application tables/indexes cause the most load or contention?
‱  Network I/O
‱  What is the network load like? How long do sessions idle?
‱  Users/Hosts/Accounts
‱  Which application users, hosts, accounts are consuming the most resources?
‱  Summaries
‱  Aggregated statistics grouped by thread, user, host, account or object
MySQL 5.6.3 – Performance Schema Instrumentation
Improved Database Profiling/Application Tuning‹
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
Next Steps
Learn More
Evaluate MySQL 5.6 Book a Workshop
HA Solutions
Guide
http://bit.ly/NB8up1
Download Today
http://dev.mysql.com/
downloads/mysql/
High Availability
Jumpstart
http://www.mysql.com/
consulting/
Copyright 2011 Oracle Corporation
Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
mark.swarbrick@oracle.com

More Related Content

PDF
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Kenny Gryp
 
PDF
Upgrade to MySQL 5.6 without downtime
Olivier DASINI
 
PDF
Tx lf propercareandfeedmysql
Dave Stokes
 
DOCX
Oracle 12c RAC On your laptop Step by Step Implementation Guide 1.0
Yury Velikanov
 
PDF
MySQL Monitoring 101
Ronald Bradford
 
PDF
MySQL High Availability with Group Replication
Nuno Carvalho
 
PDF
My sql 5.6&MySQL Cluster 7.3
Oleksii(Alexey) Porytskyi
 
PDF
New awesome features in MySQL 5.7
Zhaoyang Wang
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Kenny Gryp
 
Upgrade to MySQL 5.6 without downtime
Olivier DASINI
 
Tx lf propercareandfeedmysql
Dave Stokes
 
Oracle 12c RAC On your laptop Step by Step Implementation Guide 1.0
Yury Velikanov
 
MySQL Monitoring 101
Ronald Bradford
 
MySQL High Availability with Group Replication
Nuno Carvalho
 
My sql 5.6&MySQL Cluster 7.3
Oleksii(Alexey) Porytskyi
 
New awesome features in MySQL 5.7
Zhaoyang Wang
 

What's hot (20)

PDF
My sql 5.7-upcoming-changes-v2
Morgan Tocker
 
PDF
AUSOUG Oracle Password Security
Stefan Oehrli
 
PDF
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
PPT
Looking at RAC, GI/Clusterware Diagnostic Tools
Leighton Nelson
 
PDF
MySQL JSON Functions
Sveta Smirnova
 
ODP
MySQL Monitoring Mechanisms
Mark Leith
 
PPT
MySQL 5.6 Updates
Dave Stokes
 
PDF
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
Frederic Descamps
 
PDF
IaC MeetUp Active Directory Setup for Oracle Security LAB
Stefan Oehrli
 
PDF
Oracle Linux and Oracle Database - A Trusted Combination
Guatemala User Group
 
PDF
Everything You Need to Know About MySQL Group Replication
Nuno Carvalho
 
PPTX
Database 12c is ready for you... Are you ready for 12c?
Performance Tuning Corporation
 
PPTX
OTN Tour 2014: Rac 11g vs 12c
Deiby GĂłmez
 
PDF
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Dave Stokes
 
PDF
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Dave Stokes
 
PDF
Performance schema and sys schema
Mark Leith
 
PDF
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
Dave Stokes
 
PDF
MythBusters Globalization Support - Avoid Data Corruption
Christian Gohmann
 
PDF
REST in Piece - Administration of an Oracle Cluster/Database using REST
Christian Gohmann
 
PDF
MySQL 5.7 in a Nutshell
Emily Ikuta
 
My sql 5.7-upcoming-changes-v2
Morgan Tocker
 
AUSOUG Oracle Password Security
Stefan Oehrli
 
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
Looking at RAC, GI/Clusterware Diagnostic Tools
Leighton Nelson
 
MySQL JSON Functions
Sveta Smirnova
 
MySQL Monitoring Mechanisms
Mark Leith
 
MySQL 5.6 Updates
Dave Stokes
 
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
Frederic Descamps
 
IaC MeetUp Active Directory Setup for Oracle Security LAB
Stefan Oehrli
 
Oracle Linux and Oracle Database - A Trusted Combination
Guatemala User Group
 
Everything You Need to Know About MySQL Group Replication
Nuno Carvalho
 
Database 12c is ready for you... Are you ready for 12c?
Performance Tuning Corporation
 
OTN Tour 2014: Rac 11g vs 12c
Deiby GĂłmez
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Dave Stokes
 
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Dave Stokes
 
Performance schema and sys schema
Mark Leith
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
Dave Stokes
 
MythBusters Globalization Support - Avoid Data Corruption
Christian Gohmann
 
REST in Piece - Administration of an Oracle Cluster/Database using REST
Christian Gohmann
 
MySQL 5.7 in a Nutshell
Emily Ikuta
 
Ad

Viewers also liked (19)

PDF
Webinar 2013 advanced_query_tuning
晓 摹
 
PDF
MySQL Performance Tuning: Top 10 Tips
OSSCube
 
ODP
Performance Tuning
Ligaya Turmelle
 
PDF
攅析My sqläș‹ćŠĄéš”çŠ»çș§ćˆ«äžŽé” seanlook
晓 摹
 
PPTX
MySQL Performance Tips & Best Practices
Isaac Mosquera
 
PPTX
Mysql performance tuning
Philip Zhong
 
PDF
MySQL Performance Tuning fĂŒr Entwickler
FromDual GmbH
 
PDF
MySQL Server Settings Tuning
guest5ca94b
 
KEY
Perf Tuning Short
Ligaya Turmelle
 
PDF
MySQL Performance Tuning Variables
FromDual GmbH
 
PDF
MySQL Performance Tuning
FromDual GmbH
 
PDF
Performance Tuning Best Practices
webhostingguy
 
PDF
Join-fu: The Art of SQL Tuning for MySQL
ZendCon
 
PPTX
MySQL Indexing - Best practices for MySQL 5.6
MYXPLAIN
 
PDF
MySQLæŸ„èŻąäŒ˜ćŒ–æ”…æž
frogd
 
PDF
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
PDF
Mysql Explain Explained
Jeremy Coates
 
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
PDF
How to Design Indexes, Really
Karwin Software Solutions LLC
 
Webinar 2013 advanced_query_tuning
晓 摹
 
MySQL Performance Tuning: Top 10 Tips
OSSCube
 
Performance Tuning
Ligaya Turmelle
 
攅析My sqläș‹ćŠĄéš”çŠ»çș§ćˆ«äžŽé” seanlook
晓 摹
 
MySQL Performance Tips & Best Practices
Isaac Mosquera
 
Mysql performance tuning
Philip Zhong
 
MySQL Performance Tuning fĂŒr Entwickler
FromDual GmbH
 
MySQL Server Settings Tuning
guest5ca94b
 
Perf Tuning Short
Ligaya Turmelle
 
MySQL Performance Tuning Variables
FromDual GmbH
 
MySQL Performance Tuning
FromDual GmbH
 
Performance Tuning Best Practices
webhostingguy
 
Join-fu: The Art of SQL Tuning for MySQL
ZendCon
 
MySQL Indexing - Best practices for MySQL 5.6
MYXPLAIN
 
MySQLæŸ„èŻąäŒ˜ćŒ–æ”…æž
frogd
 
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
Mysql Explain Explained
Jeremy Coates
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Aurimas Mikalauskas
 
How to Design Indexes, Really
Karwin Software Solutions LLC
 
Ad

Similar to MySQL Webinar 2/4 Performance tuning, hardware, optimisation (20)

PDF
2012 replication
sqlhjalp
 
PDF
MySQL for Oracle DBA -- Rocky Mountain Oracle User Group Training Days '15
Dave Stokes
 
PDF
MySQL 5.6 Replication Webinar
Mark Swarbrick
 
PDF
2012 scale replication
sqlhjalp
 
PPTX
MySQL High Availibility Solutions
Mark Swarbrick
 
PDF
2012 ohiolinuxfest replication
sqlhjalp
 
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
PPTX
MySQL High Availability Solutions - Feb 2015 webinar
Andrew Morgan
 
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
PDF
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 
PDF
Scaling MySQL -- Swanseacon.co.uk
Dave Stokes
 
PPTX
ConFoo MySQL Replication Evolution : From Simple to Group Replication
Dave Stokes
 
PDF
Sunshine php my sql 8.0 v2
Kathy Forte (Hassard)
 
PDF
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
PDF
MySQL Replication Troubleshooting for Oracle DBAs
Sveta Smirnova
 
PDF
MySQL Cluster Asynchronous replication (2014)
Frazer Clement
 
PDF
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
PDF
Confoo 202 - MySQL Group Replication and ReplicaSet
Dave Stokes
 
ODP
MySQL for Oracle DBAs
Ben Krug
 
PDF
Introduction to MySQL
Ted Wennmark
 
2012 replication
sqlhjalp
 
MySQL for Oracle DBA -- Rocky Mountain Oracle User Group Training Days '15
Dave Stokes
 
MySQL 5.6 Replication Webinar
Mark Swarbrick
 
2012 scale replication
sqlhjalp
 
MySQL High Availibility Solutions
Mark Swarbrick
 
2012 ohiolinuxfest replication
sqlhjalp
 
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
MySQL High Availability Solutions - Feb 2015 webinar
Andrew Morgan
 
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 
Scaling MySQL -- Swanseacon.co.uk
Dave Stokes
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
Dave Stokes
 
Sunshine php my sql 8.0 v2
Kathy Forte (Hassard)
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
MySQL Replication Troubleshooting for Oracle DBAs
Sveta Smirnova
 
MySQL Cluster Asynchronous replication (2014)
Frazer Clement
 
MySQL & Oracle Linux Keynote at Open Source India 2014
Sanjay Manwani
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Dave Stokes
 
MySQL for Oracle DBAs
Ben Krug
 
Introduction to MySQL
Ted Wennmark
 

More from Mark Swarbrick (20)

PDF
MySQL NoSQL Document Store
Mark Swarbrick
 
PPSX
MySQL @ the University Of Nottingham
Mark Swarbrick
 
PDF
InnoDb Vs NDB Cluster
Mark Swarbrick
 
PDF
MySQL Security & GDPR
Mark Swarbrick
 
PDF
Intro To MySQL 2019
Mark Swarbrick
 
PDF
MySQL 8
Mark Swarbrick
 
PDF
MySQL Dublin Event Nov 2018 - MySQL 8
Mark Swarbrick
 
PDF
MySQL Dublin Event Nov 2018 - State of the Dolphin
Mark Swarbrick
 
PDF
Oracle Code Event - MySQL JSON Document Store
Mark Swarbrick
 
PDF
TLV - MySQL Security overview
Mark Swarbrick
 
PDF
TLV - MySQL Enterprise Edition + Cloud
Mark Swarbrick
 
PDF
TLV - Whats new in MySQL 8
Mark Swarbrick
 
PDF
MySQL At University Of Nottingham - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL At Mastercard - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL 8 - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL Security + GDPR - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL InnoDB + NDB Cluster - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL Cloud - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL 2018 Intro - 2018 MySQL Days
Mark Swarbrick
 
PDF
MySQL + GDPR
Mark Swarbrick
 
MySQL NoSQL Document Store
Mark Swarbrick
 
MySQL @ the University Of Nottingham
Mark Swarbrick
 
InnoDb Vs NDB Cluster
Mark Swarbrick
 
MySQL Security & GDPR
Mark Swarbrick
 
Intro To MySQL 2019
Mark Swarbrick
 
MySQL 8
Mark Swarbrick
 
MySQL Dublin Event Nov 2018 - MySQL 8
Mark Swarbrick
 
MySQL Dublin Event Nov 2018 - State of the Dolphin
Mark Swarbrick
 
Oracle Code Event - MySQL JSON Document Store
Mark Swarbrick
 
TLV - MySQL Security overview
Mark Swarbrick
 
TLV - MySQL Enterprise Edition + Cloud
Mark Swarbrick
 
TLV - Whats new in MySQL 8
Mark Swarbrick
 
MySQL At University Of Nottingham - 2018 MySQL Days
Mark Swarbrick
 
MySQL At Mastercard - 2018 MySQL Days
Mark Swarbrick
 
MySQL 8 - 2018 MySQL Days
Mark Swarbrick
 
MySQL Security + GDPR - 2018 MySQL Days
Mark Swarbrick
 
MySQL InnoDB + NDB Cluster - 2018 MySQL Days
Mark Swarbrick
 
MySQL Cloud - 2018 MySQL Days
Mark Swarbrick
 
MySQL 2018 Intro - 2018 MySQL Days
Mark Swarbrick
 
MySQL + GDPR
Mark Swarbrick
 

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PPTX
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
PDF
Software Development Company | KodekX
KodekX
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
This slide provides an overview Technology
mineshkharadi333
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Architecture of the Future (09152021)
EdwardMeyman
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
Software Development Company | KodekX
KodekX
 

MySQL Webinar 2/4 Performance tuning, hardware, optimisation

  • 1. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012
  • 2. Installation, Configuration and performance tuning Mark Swarbrick Principle Presales Consultant MySQL Webinar Series 2/4
  • 3. Program Agenda Â§ï‚§â€Ż Hardware Specification Â§ï‚§â€Ż Setting up Replication Â§ï‚§â€Ż Performance tuning
  • 4. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Safe Harbor Statement
  • 6. MySQL Hardware / Software Platforms MySQL is supported on a variety of hardware / software platforms: Oracle Linux Oracle Solaris Red Hat Canonical (Ubuntu) SUSE Debian Microsoft Windows XP/Vista/7/2003/2008/2012/server FreeBSD HPUX Other Linux – Fedora / OpenSUSE / CentOS etc
  • 7. MySQL Hardware / Software Platforms MySQL is supported on a variety of hardware / software platforms: X86 X86_64 X86_IA64 SPARC_32 SPARC_64 IBM Power5_64 PA-RISC 2.0 We will support with best efforts on other hardware platforms such as ARM. For example MySQL Cluster compiled to run on a raspberry pi!
  • 8. Copyright Oracle Corporation 2014 | <date>8 Scaling on dense, multi-core, multi-thread servers ‱  10s - 100GBs RAM ‱  SSDs Scale across cores within a single instance You can get a long way with MySQL 5.6! The Path to Scalability Scaling-Up can take you a long way
  • 9. MySQL Hardware / Software Platforms Server: Having the fastest CPU is still beneficial. Can use as many as 32 cores! OS choice and tuning is important, but Linux / Solaris or windows all give good performance. Storage: Don’t use slow disks Flash memory (SSD etc) helps for random access (reads are the most costly) FS is important – ZFS, UFS, QFS, VxFS, EXT3, EXT4 XFS etc.. Use of O_Direct if O/S supports it Don’t forget the network! Faster is better!
  • 10. Hardware: The Perfect MySQL Server ‱  The more cores the better (especially for 5.5 and later) ‱  x86_64 - 64 bit for more memory is important –  The more the better ‱  Fast HD (10-15k RPM SATA) or NAS/SAN

 –  RAID 10 for most, RAID 5 OK if very read intensive –  Hardware RAID battery backed up cache critical! –  More disks are always better! - 4+ recommended, 8-16 can increase IO ‱  
Or SSD (for higher throughput) –  Intel, Fusion-IO good choices; good option for Slaves ‱  At least 2 x NICs for redundancy ‱  Slaves should be as powerful as the Master
  • 12. MySQL HA Solutions Note that MySQL Fabric is currently at Release Candidate Status
  • 13. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13 Why Replicate? Â§ï‚§â€Ż Duplicates database from a “master” to a “slave” Â§ï‚§â€Ż Redundant copies of the data provide foundation for High Availability Â§ï‚§â€Ż Scale out by distributing queries across the replication cluster Master Slaves Web / App Servers Writes & Reads Reads
  • 14. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14 Slave Database Â§ï‚§â€Ż Session thread: processes queries from the application – writes data to master database & associated events to binary log Â§ï‚§â€Ż Dump thread: reads events from binary log and sends them to a slave Â§ï‚§â€Ż I/O thread: receives replication events and stores them in slave’s relay log Â§ï‚§â€Ż SQL thread: reads replication events from slave’s relay log and applies them to slave database Session Binary Log Master Database Dump I/O Relay Log SQL Replication Workflow
  • 15. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15 ReplicationReplication Solutions
  • 16. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16 Async Replication
  • 17. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17 Semi-sync Replication
  • 18. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18 MySQL 5.6: Transforming Replication ‱  Multi-Threaded Slaves ‱  Binary Log Group Commit ‱  Optimized Row-Based Replication PERFORMANCE ‱  Global Transaction Identifiers ‱  Replication Failover & Admin Utilities ‱  Crash Safe Slaves & Binlogs FAILOVER & RECOVERY ‱  Replication Event Checksums DATA INTEGRITY ‱  Replication Utilities ‱  Time-Delayed Replication ‱  Remote Binlog Backup ‱  Informational Log Events ‱  Server UUIDs DEV/OPS AGILITY
  • 19. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19 5x Higher Performance with MySQL 5.6 0 5 10 QPS 58.11 144.4 282.53 0 50 100 150 200 250 300 QueriesperSecond Worker Threads Multi-Threaded Slave Performance
  • 20. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20 Master GTID=123456 GTID=123456 GTID=123456 GTID=123456 Global Transaction Identifiers Â§ï‚§â€Ż Simple to track & compare replication across the farm Â§ï‚§â€Ż Unique identifier for each transaction written to the Binlog Â§ï‚§â€Ż Automatically identify the most up-to-date slave for failover Â§ï‚§â€Ż Deploy n-tier replication hierarchies
  • 21. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21 Time Delayed Replication - configuring slave2> CHANGE MASTER TO -> MASTER_HOST = 'localhost‘, -> MASTER_PORT = 3306, -> MASTER_USER = 'repl_user‘, -> MASTER_PASSWORD = ‘sun123!‘, -> MASTER_DELAY = 600; slave2> START SLAVE;
  • 22. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22 MySQL Utilities Â§ï‚§â€Ż Automate common Dev/Ops tasks Â§ï‚§â€Ż Replication: provisioning, testing, monitoring and failover Â§ï‚§â€Ż Database comparisons: consistency checking Â§ï‚§â€Ż Database administration: users, connections, tables, etc Â§ï‚§â€Ż New utilities in development, i.e. log analysis Â§ï‚§â€Ż Implemented as Python scripts, plug-in for MySQL Workbench Â§ï‚§â€Ż Extensible to include custom scripting Â§ï‚§â€Ż Resources: Documentation & Community Forum Â§ï‚§â€Ż http://dev.mysql.com/doc/workbench/en/mysql-utils-man.html Â§ï‚§â€Ż http://forums.mysql.com/list.php?155
  • 23. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23 Utility Workflow for Replication Â§ï‚§â€Ż Replicate: Initiates Replication to the new slave Â§ï‚§â€Ż Check: Validates the replication configuration and operation Â§ï‚§â€Ż Show: Display Replication topology Â§ï‚§â€Ż Fail-Over & Admin: Detects and failovers (or switches) from master to slave. Status monitoring Check Show Fail-Over & AdminReplicate
  • 24. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24 mysqlreplicate Utility Â§ï‚§â€Ż Starts replication process Â§ï‚§â€Ż User can provide login and connection parameters for the master Â§ï‚§â€Ż Configurable replication start points: current position / GTID, specific event, entire binlog Â§ï‚§â€Ż Checks storage engine compatibility Â§ï‚§â€Ż Enables fast, simple scaling New Slave Login, Connection & Start-Point Master Replication configured, binlog position Repl
  • 25. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25 mysqlreplicate example $ mysqlreplicate --master=root:billy@localhost:3306 --slave=root:billy@localhost:3307 # master on localhost: ... connected. # slave on localhost: ... connected. Repl
  • 26. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26 mysqlrplshow Utility Â§ï‚§â€Ż Discovers & displays replication topology Â§ï‚§â€Ż Shows slaves attached to each master Â§ï‚§â€Ż Labels each slave with hostname and port number Â§ï‚§â€Ż Displays multiple topologies, including hierarchical and circular Â§ï‚§â€Ż Displays results in a graph or list Â§ï‚§â€Ż Enables user to monitor topology on-demand $ mysqlrplshow --master=root@localhost:3311 # master on localhost: ... connected. # Finding slaves for master: localhost:3311 # Replication Topology Graph:: localhost:3306 (MASTER) | +--- localhost:3307 - (SLAVE) | +--- localhost:3308 - (SLAVE + MASTER) | +--- localhost:3313 - (SLAVE) Show
  • 27. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27 mysqlrplcheck Utility Â§ï‚§â€Ż Tests replication on master and slave to ensure proper configuration of replication Â§ï‚§â€Ż Checks binlog is enabled and displays any configured exceptions Â§ï‚§â€Ż Checks slave access and privileges to master Â§ï‚§â€Ż Checks slave connection status Â§ï‚§â€Ż Checks for conflicts in master.info file (or mysql.slave_master_info table) Â§ï‚§â€Ż Checks storage engine compatibility Â§ï‚§â€Ż Tests executed sequentially Â§ï‚§â€Ż Reports status of each test Â§ï‚§â€Ż Simple verification of deployment & fast fault resolution Check
  • 28. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28 mysqlrplcheck example $ mysqlrplcheck --master=root@host1:3310 --slave=root@host2:3311 # master on host1: ... connected. # slave on host2: ... connected. Test Description Status ------------------------------------------------------------- Checking for binary logging on master [pass] Are there binlog exceptions? [pass] Replication user exists? [pass] Checking server_id values [pass] Is slave connected to master? [pass] Check master information file [pass] Checking InnoDB compatibility [pass] Checking storage engines compatibility [pass] Checking lower_case_table_names settings [pass] Checking slave delay (seconds behind master) [pass] # ...done. Check
  • 29. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29 Replication Administration Utility Â§ï‚§â€Ż Perform switchover to eliminate downtime during planned maintenance Â§ï‚§â€Ż Start and stop slaves Â§ï‚§â€Ż Slave discovery & monitoring Â§ï‚§â€Ż Slave status, thread status Â§ï‚§â€Ż Replication processing, including any lag Â§ï‚§â€Ż Configure slave promotion policies Master Slaves Administration Utility Status & Switchover Admin
  • 30. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30 Planned switchover to new master with mysqlrpladmin $ mysqlrpladmin --master=root@rod:3306 --slaves=root@jane:3306,root@jane:3307,root@freddy:3306 --new-master=root@jane:3306 --demote-master switchover # Performing switchover from master at rod:3306 to slave at jane:3306. # Checking candidate slave prerequisites. # Waiting for slaves to catch up to old master. # Stopping slaves. # Performing STOP on all slaves. # Demoting old master to be a slave to the new master. # Switching slaves to new master. # Starting all slaves. # Performing START on all slaves. # Checking slaves for errors. # Switchover complete. # ...done. Switch- Over
  • 31. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31 Â§ï‚§â€Ż Enabling self-healing replication topologies Â§ï‚§â€Ż Automated failover & recovery Â§ï‚§â€Ż mysqlfailover Utility Â§ï‚§â€Ż Switchover & administration Â§ï‚§â€Ż mysqlrpladmin Utility Â§ï‚§â€Ż Fully configurable slave promotion policies Â§ï‚§â€Ż Delivers HA within the core MySQL distribution HA UtilitiesMonitoring Failed Master Slaves Promoted Master Fail-Over & Admin Replication HA Utilities
  • 32. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32 mysqlfailover – monitoring resumes MySQL Replication Monitor and Failover Utility Failover Mode = auto Next Interval = Mon Mar 19 16:05:12 2012 Master Information ------------------ Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB mysql-bin.000001 1117 GTID Executed Set A0F7E82D-3554-11E2-9950-080027685B56:1-5 UUIDs +------------+-------+---------+--------+------------+---------+ | host | port | role | state | gtid_mode | health | +------------+-------+---------+--------+------------+---------+ | jane | 3306 | MASTER | UP | ON | OK | | jane | 3307 | SLAVE | UP | ON | OK | | freddy | 3306 | SLAVE | UP | ON | OK | +------------+-------+---------+--------+------------+---------+ Fail-Over
  • 33. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33 mysqlfailover – master failed Failover starting... # Candidate slave jane:3306 will become the new master. # Preparing candidate for failover. # Creating replication user if it does not exist. # Stopping slaves. # Performing STOP on all slaves. # Switching slaves to new master. # Starting slaves. # Performing START on all slaves. # Checking slaves for errors. # Failover complete. # Discovering slaves for master at jane:3306 Failover console will restart in 5 seconds. Fail-Over
  • 34. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34 An extensible and easy-to- use framework for managing a farm of MySQL server supporting high- availability and sharding MySQL Fabric
  • 35. Copyright Oracle Corporation 2014 | <date>35 MySQL Fabric Framework (HA) All Data Primary Secondary Extra Read Replicas MySQL Fabric Controller SQL Queries State & Routing Info HA Group Coordination and Control
  • 36. Copyright Oracle Corporation 2014 | <date>36 MySQL Replication & MySQL Fabric HA Â§ï‚§â€Ż MySQL Replication is the initial implementation used in HA Groups –  PRIMARY = Replication Master & receives all writes Â§ï‚§â€Ż Failover –  MySQL Fabric detects failure of PRIMARY/Master –  Selects a SECONDARY/Slave and promotes it –  Updates State Store –  Updated state fetched by Fabric-aware connectors & how this effects failover
  • 37. Copyright Oracle Corporation 2014 | <date>37 High-Availability Group Concept Â§ï‚§â€Ż Abstract Concept –  Set of servers –  Server attributes Â§ï‚§â€Ż Connector Attributes –  Connection information –  Mode: read-only, read-write, ... –  Weight: distribute load Â§ï‚§â€Ż Management Attributes –  State: state/role of the server State: Primary Mode: Read-Write Host: server-1.example.com
  • 38. Copyright Oracle Corporation 2014 | <date>38 Create HA Groups and add Servers Â§ï‚§â€Ż Define a group mysqlfabric group create my_group Â§ï‚§â€Ż Add servers to group mysqlfabric group add my_group server1.example.com mysqlfabric group add my_group server2.example.com
  • 39. Copyright Oracle Corporation 2014 | <date>39 Create HA Groups and add Servers Â§ï‚§â€Ż Promote one server to be primary mysqlfabric group promote my_group Â§ï‚§â€Ż Tell failure detector to monitor group mysqlfabric group activate my_group
  • 40. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40 Â§ï‚§â€Ż Performance Tuning
  • 41. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41 The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Rules of Tuning‹ ‱  Never make a change in production first ‱  Have a good benchmark or reliable load ‱  Start with a good baseline ‱  Only change 1 thing at a time –  identify a set of possible changes –  try each change separately –  try in combinations of 2, then 3, etc. ‱  Monitor the results –  Query performance - query analyzer, slow query log, etc. ‱  throughput ‱  single query time ‱  average query time –  CPU - top, vmstat, dstat –  IO - iostat, top, vmstat, bonnie++, dstat –  Network bandwidth ‱  Document and save the results
  • 42. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Were do I find a benchmark? ‱  Make your own –  Can use general query log output –  Could use MySQL Proxy and TCP Dump ‱  DBT2 –  http://osdldbt.sourceforge.net/ –  http://samurai-mysql.blogspot.com/2009/03/settingup-dbt-2.html ‱  mysqlslap MySQL 5.1 + –  http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html ‱  SysBench –  http://sysbench.sourceforge.net/ ‱  supersmack –  http://vegan.net/tony/supersmack/ ‱  mybench –  http://jeremy.zawodny.com/mysql/mybench/
  • 43. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle InnoDB Tuning‹ ‱  Unlike MyISAM - InnoDB uses a single cache for both index and data –  innodb_buffer_pool_size - should be 70-80% of available memory. –  It is not uncommon for this to be very large, i.e. 34GB on a system with 40GB of memory –  Make sure its not set so large as to cause swapping! –  mysql>show status like 'Innodb_buffer%' ; ‱  InnoDB can use direct IO on systems that support it - Linux, FreeBSD, and Solaris –  innodb_flush_method = O_DIRECT ‱  For more InnoDB tuning see –  http://dev.mysql.com/doc/refman/5.1/en/innodb-tuning- troubleshooting.html
  • 44. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle DBT-2 (W200) Transactions per Minute %user %iowait Buffer pool 1G 1125.44 2% 30% Buffer pool 2G 1863.19 3% 28% Buffer pool 5G 4385.18 5.5% 33% Buffer pool 30G (All data in cache) 36784.76 36% 8% Cache hot application data in memory‹ ‱  DBT-2 benchmark (write intensive) ‱  20-25GB hot data (200 warehouses, running 1 hour) ‱  Nehalem 2.93GHz x 8 cores, MySQL 5.5.2, 4 RAID1+0 HDDs ‱  RAM size affects everything. Not only for SELECT, but also for INSERT/UPDATE/DELETE –  INSERT: Random reads/writes happen when inserting into indexes in random order –  UPDATE/DELETE: Random reads/writes happen when modifying records
  • 45. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Connections‹ ‱  MySQL Caches the threads used by a connection –  thread_cache_size - Number of threads to cache –  Setting this to 100 or higher is not unusual ‱  Monitor Threads_created to see if this is an issue –  Counts connections not using the thread cache –  Should be less than 1-2 a minute –  Usually only an issue if more than 1-2 a second ‱  Only an issue if you create and drop a lot of connections, i.e. PHP ‱  Overhead is usually about 250k per thread ‱  Aborted_clients - http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html ‱  Aborted_connections - http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
  • 46. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Sessions‹ ‱  Some session variables control space allocated by each session (per connection) –  Setting these to small can give bad performance –  Setting these too large can cause the server to swap! –  Can be set by connection ‱  SET SORT_BUFFER_SIZE=1024*1024*128 –  Set small by default, increase in connections that need it ‱  sort_buffer_size - Used for ORDER BY, GROUP ‱  BY, SELECT DISTINCT, UNION DISTINCT –  Monitor Sort_merge_passes < 1-2 an hour optimal –  Usually a problem in a reporting or data warehouse database ‱  Other important session variables –  read_rnd_buffer_size - Set to 1/2 sort_buffer_size –  join_buffer_size - Watch Select_full_join –  read_buffer_size - Used for full table scans, watch Select_scan –  tmp_table_size - Max temp table size in memory, watch Created_tmp_disk_tables
  • 47. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Query Cache‹ ‱  MySQL’s ‘Jekyll and Hyde’ of performance tuning options, when it is useful it really helps, when it hurts, it really hurts ‱  MySQL Query Cache caches both the query and the full result set –  query_cache_type - Controls behaviour ‱  0 or OFF - Not used (buffer may still be allocated) ‱  1 or ON cache all unless SELECT SQL_NO_CACHE (DEFAULT) ‱  2 or DEMAND cache none unless SELECT SQL_CACHE –  query_cache_size - Determines the size of the cache ‱  mysql> show status like 'Qc%' ; ‱  Gives great performance if: –  Identical queries returning identical data are used often –  No or rare inserts, updates or deletes ‱  Best Practice –  Set to DEMAND –  Add SQL_CACHE to appropriate queries
  • 49. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Indexes in MySQL‹ ‱  Indexes allow for faster access to data ‱  Data accessed via an index is usually in sorted order ‱  Unique or Primary - Must refer to only one record ‱  Non-Unique - May refer to many records ‱  Can be on one or more columns –  CREATE INDEX IDX ON TAB1(col1,col2,col3) ; ‱  Can use prefix index for –  CHAR, VARCHAR, BINARY, and VARBINARY –  CREATE INDEX PRE ON TAB1(COL1(10)) ; –  Prefix is in bytes, not characters ‱  Very useful for large strings ‱  Works best when leading part of column is selective
  • 50. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Index Best Practices‹ ‱  Too many indexes can slow down inserts/deletes –  Use only the indexes you must have –  Check often –  mysql>show create table tabname ; ‱  Don’t duplicate leading parts of compound keys –  index key123 (col1,col2,col3) –  index key12 (col1,col2) <- Not needed! –  index key1 (col1) <-- Not needed! ‱  Use prefix indexes on large keys ‱  Best indexes are 16 bytes/chars or less (> 16 text?) ‱  Indexes bigger than 32 bytes/chars should be looked at very closely –  should have there own cache if in MyISAM ‱  For large strings that need to be indexed, i.e. URLs, consider using a separate column using the MySQL MD5 to create a hash key and index on it instead
  • 51. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ; +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ | 1 | SIMPLE | C | ALL | NULL | NULL | NULL | NULL | 239 | Using where | | 1 | SIMPLE | Y | ALL | NULL | NULL | NULL | NULL | 4079 | Using where; Using join buffer | | 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index | +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------------+ 3 rows in set (0.00 sec) (Using the MySQL World database) http://dev.mysql.com/doc/index-other.html Explain ‹ ‱  Order that the tables are accessed ‱  Indexes used ‱  Estimated number of rows accessed per table ‱  select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ;
  • 52. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Explain - Details‹ ‱  Tables are accessed from top to bottom ‱  Columns –  Select Type - SELECT if no Union or Subquery –  Table, uses aliases –  Type - Most common ref or eq_ref –  Possible Keys - Indexes the optimizer is considering –  Key = The index the optimizer chose –  Ref - What column in what table (using alias) is referenced by the index –  Rows - Estimated number of rows per reference ‱  Multiple these to get overall cost ‱  There are more values, see: ‱  http://dev.mysql.com/doc/refman/5.6/en/using-explain.html
  • 53. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle mysql> explain select C.Name, Y.Name, Y.Population, Language from Country as C, City as Y, CountryLanguage as L where Y.Name = C.Name and L.CountryCode = Y.CountryCode and C.Name = 'Macao' ; +----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ | 1 | SIMPLE | C | ref | c2 | c2 | 52 | const | 1 | Using where; Using index | | 1 | SIMPLE | Y | ref | c2 | c2 | 35 | const | 1 | Using where | | 1 | SIMPLE | L | ref | PRIMARY | PRIMARY | 3 | world.Y.CountryCode | 9 | Using index |+----+-------------+-------+------+---------------+---------+---------+---------------------+------+--------------------------+ 3 rows in set (0.00 sec) More Explain‹ ‱  alter table Country add index c2 (Name) ; ‱  alter table City add index c2 (Name) ; ‱  The original cost was 239 * 4079 * 9 = 8,773,929 ‱  The new cost is 1 * 1 * 9 = 9
  • 55. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Queries‹ ‱  Often the # 1 issue in overall performance ‱  Always, Always have your slow query log on! –  http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html –  Use: log_queries_not_using_indexes –  Check it regularly –  Use mysqldumpslow : http://dev.mysql.com/doc/refman/5.1/en/mysqldumpslow.html –  Best practice is to automate running mysqldumpslow every morning and email results to DBA, DBDev, etc. ‱  Understand and use EXPLAIN –  http://dev.mysql.com/doc/refman/5.1/en/using-explain.html ‱  Select_scan - Number of full table scans ‱  Select_full_join - Joins without indexes ‱  MySQL Query Analyzer –  http://www.mysql.com/products/enterprise/query.html
  • 57. The World’s Most Popular Open Source DatabaseCopyright 2010 Oracle Schemas‹ ‱  Size = performance, smaller is better –  Size right! Do not automatically use 255 for VARCHAR ‱  Temp tables, most caches, expand to full size ‱  Use “procedure analyse” to determine the optimal types given the values in your table –  http://dev.mysql.com/doc/refman/5.1/en/procedure-analyse.html –  mysql> select * from tab procedure analyse (64,2000) G ‱  Consider the types: –  enum : http://dev.mysql.com/doc/refman/5.1/en/enum.html –  set : http://dev.mysql.com/doc/refman/5.1/en/set.html ‱  Compress large strings –  Use the MySQL COMPRESS and UNCOMPRESS functions –  Very important in InnoDB 5.5, now with barracuda not so bad
  • 58. Partitioning can help performance lïŹâ€Ż Single inserts and selects faster lïŹâ€Ż Range selects faster lïŹâ€Ż More efficiently split the data across different paths lïŹâ€Ż Historical data stored efficiently lïŹâ€Ż delete large chunks of data (drop partition) lïŹâ€Ż Move from table to partition easy 5.6
  • 59. MySQL 5.6 Performance Schema ‱  PERFORMANCE_SCHEMA presents low level MySQL performance information ‱  Data can be cleared ‱  Filters with WHERE are allowed ‱  Must be enabled with --performance_schema mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT -> FROM EVENTS_WAITS_HISTORY WHERE THREAD_ID = 13 -> ORDER BY EVENT_ID; +----------+-----------------------------------------+------------+ | EVENT_ID | EVENT_NAME | TIMER_WAIT | +----------+-----------------------------------------+------------+ | 86 | wait/synch/mutex/mysys/THR_LOCK::mutex | 686322 | | 87 | wait/synch/mutex/mysys/THR_LOCK_malloc | 320535 | | 88 | wait/synch/mutex/mysys/THR_LOCK_malloc | 339390 | | 89 | wait/synch/mutex/mysys/THR_LOCK_malloc | 377100 | | 90 | wait/synch/mutex/sql/LOCK_plugin | 614673 | | 91 | wait/synch/mutex/sql/LOCK_open | 659925 | | 92 | wait/synch/mutex/sql/THD::LOCK_thd_data | 494001 | | 93 | wait/synch/mutex/mysys/THR_LOCK_malloc | 222489 | | 94 | wait/synch/mutex/mysys/THR_LOCK_malloc | 214947 | | 95 | wait/synch/mutex/mysys/LOCK_alarm | 312993 | +----------+-----------------------------------------+------------+ mysql> UPDATE SETUP_INSTRUMENTS -> SET ENABLED = 'NO' -> WHERE NAME = 'wait/synch/mutex/myisammrg/MYRG_INFO::mutex'; mysql> UPDATE SETUP_CONSUMERS -> SET ENABLED = 'NO' WHERE NAME = 'file_summary_by_instance'; © 2010 Oracle Corporation – Proprietary and Confidential
  • 60. ‱  Statements/Stages ‱  What are my most resource intensive queries? Where do they spend time? ‱  Table/Index I/O, Table Locks ‱  Which application tables/indexes cause the most load or contention? ‱  Network I/O ‱  What is the network load like? How long do sessions idle? ‱  Users/Hosts/Accounts ‱  Which application users, hosts, accounts are consuming the most resources? ‱  Summaries ‱  Aggregated statistics grouped by thread, user, host, account or object MySQL 5.6.3 – Performance Schema Instrumentation Improved Database Profiling/Application Tuning‹
  • 61. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 Next Steps Learn More Evaluate MySQL 5.6 Book a Workshop HA Solutions Guide http://bit.ly/NB8up1 Download Today http://dev.mysql.com/ downloads/mysql/ High Availability Jumpstart http://www.mysql.com/ consulting/ Copyright 2011 Oracle Corporation
  • 62. Copyright © 2012, Oracle and / or its affiliates. All rights reserved. September 29th, 2012 [email protected]