Beruflich Dokumente
Kultur Dokumente
Program Agenda
1
Introduction
More information
Introduction
MySQL architecture
Click icon to add picture
Base
- Installation layout
- Log files
Connectors
- Clients
- APIs
Optimizer
Caches & buffers
Storage engines
Management
Configurable
You can setup custom path for each
component
Including custom path for tables
Connectors
The way you connect to MySQL Server
Clients
MySQL CLI
MySQL Workbench
MySQL Enterprise Monitor (MEM)
Oracle Enterprise Manager with MEM plugin
APIs
Exist for most popular programming languages
C, C++, JDBC, PHP, Python, Net, ODBC
Plugins
MySQL Server is highly configurable via plugins
Storage engines
Full-text parsers
Daemon
INFORMATION_SCHEMA
Semisynchronous Replication
Audit
Authentication
Password-validation
Protocol Trace
5.7
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
Storage engines
From troubleshooting point of view
Own data
Own index format
Own locking model
Own diagnostic
Own log files
CHECK TABLE
Socket (Unix)
mysql> select user, host from mysql.user order by user desc, host desc;
+------+------------+
| user | host
+------+------------+
| root | localhost
| root | delly
| root | ::1
| root | 127.0.0.1
| foo
| %
| localhost
+------+------------+
6 rows in set (0.00 sec)
Grant tables
mysql.db
mysql.tables_priv
mysql.columns_priv
mysql.procs_priv
mysql.proxies_priv
+--------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION|
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION
+--------------------------------------------------------------------+
2 rows in set (0.02 sec)
+-----------------------------------------------------+
| GRANT USAGE ON *.* TO 'foo'@'%'
+-----------------------------------------------------+
2 rows in set (0.02 sec)
Error handling
Errors vs warnings
| Code
| Message
+-----------+--------+----------------------------------------------------+
| Warning
| 1292
+-----------+--------+----------------------------------------------------+
1 row in set (0.00 sec)
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
Error information
mysql_errno
mysql_error
Warnings
mysql_info
mysql_sqlstate
mysql_warning_count
Error handling
perror
2:
Error handling
In stored routines
GET DIAGNOSTICS
code = RETURNED_SQLSTATE,
http://dev.mysql.com/doc/refman/5.6/en/diagnostics-area.html
Global
Session
http://dev.mysql.com/doc/refman/5.6/en/mysqld-option-tables.html
Configuration file
In default location
http://dev.mysql.com/doc/refman/5.6/en/option-files.html
Session options
Anybody
There is no limits!
Connection options
Operation-specific
GLOBAL
SESSION
Can be reset
FLUSH STATUS
Tables
Indexes
Other
InnoDB plugins
We will discuss them later
Oracle analog
MySQL Optimizer
Overview
EXPLAIN EXTENDED
EXPLAIN PARTITIONS
EXPLAIN FORMAT=JSON
INFORMATION_SCHEMA.TRACE
Status variables 'Handler_%'
Default in 5.7
EXPLAIN in Oracle
http://docs.oracle.com/cd/B10500_01/server.920/a96533/ex_plan.htm
EXPLAIN PLAN SET statement_id = 'example_plan4' FOR
SELECT h.order_number, l.revenue_amount, l.ordered_quantity
FROM so_headers_all h, so_lines_all l
WHERE h.customer_id = :b1
AND h.date_ordered > SYSDATE30
AND l.header_id = h.header_id ;
Plan
-------------------------------------------------SELECT STATEMENT
NESTED LOOPS
TABLE ACCESS BY INDEX ROWID SO_HEADERS_ALL
INDEX RANGE SCAN SO_HEADERS_N1
TABLE ACCESS BY INDEX ROWID SO_LINES_ALL
INDEX RANGE SCAN SO_LINES_N1
EXPLAIN in MySQL
mysql> EXPLAIN SELECT user, host FROM mysql.user\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: user
type: index
possible_keys: NULL
key: PRIMARY
key_len: 228
ref: NULL
rows: 4
Extra: Using index
1 row in set (0.13 sec)
EXPLAIN in MySQL
Variant: EXTENDED
mysql> EXPLAIN EXTENDED SELECT user, host FROM mysql.user\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: user
type: index
possible_keys: NULL
key: PRIMARY
key_len: 228
ref: NULL
rows: 4
filtered: 100.00
Message: /* select#1 */
select
`mysql`.`user`.`User` AS
`user`,`mysql`.`user`.`H
ost` AS `host` from
`mysql`.`user`
1 row in set (0.00 sec)
EXPLAIN in MySQL
Variant: FORMAT=JSON
...
"used_key_parts": [
"Host",
"User"
EXPLAIN: {
],
"query_block": {
"key_length": "228",
"select_id": 1,
"rows": 4,
"table": {
"filtered": 100,
"using_index": true
"table_name": "user",
"access_type": "index",
"key": "PRIMARY",
...
EXPLAIN in MySQL
More information
http://www.slideshare.net/SvetaSmirnova/troubleshooting-my-sqlperformanceaddonsen
http://dev.mysql.com/doc/refman/5.6/en/explain-output.html
MySQL EXPLAIN in Practice [HOL9232] (past)
MySQL 5.7: Whats New in the Parser and the Optimizer? [CON2830] (past)
How to Analyze and Tune MySQL Queries for Better Performance
[TUT3157] (past)
MySQL Optimizer
Handler_% status variables
mysql> flush status;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW STATUS LIKE 'Handler_read_%';
+----------------------------+-------+
| Variable_name
| Value |
+----------------------------+-------+
| Handler_read_first
| 0
| Handler_read_key
| 0
| Handler_read_last
| 0
| Handler_read_next
| 0
| Handler_read_prev
| 0
| Handler_read_rnd
| 0
| Handler_read_rnd_next
| 0
+----------------------------+-------+
7 rows in set (0.00 sec)
MySQL Optimizer
Handler_% status variables
mysql> select count(*) from employees join titles using(emp_no) where title='Senior Engineer'\G
*************************** 1. row ***************************
count(*): 97750
1 row in set (3.24 sec)
mysql> SHOW STATUS LIKE 'Handler_read_%';
+----------------------------+--------+
| Variable_name
| Value
+----------------------------+--------+
| Handler_read_first
| 1
| Handler_read_key
| 300027 |
| Handler_read_last
| 0
| Handler_read_next
| 397774 |
...
MySQL Optimizer
Other tools
INFORMATION_SCHEMA.TRACE
http://dev.mysql.com/doc/internals/en/optimizer-tracing.html
join_preparation, join_optimization,
join_execution
considered_execution_plans, refine_plan, more
http://dev.mysql.com/doc/mysql-monitor/3.0/en/mem-quan-using.html
Corruption
Index statistics
They care about physical data, so all data information are on their level
Options usually start from engine name
Shared tablespace
Optional: --innodb_file_per_table
Recommended and default since 5.6
Redo log files
MDL
Table-level
Row-level
Transactions
Server-level
MDL locks
Engine level
Table locks
Row locks
Block writes
Write locks
AUTOCOMMIT
Supported
Locking issues
Diagnostic tools
PROCESSLIST
InnoDB tables
PERFORMANCE SCHEMA
MDL locks
Table locks
Server-level transactions
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
Pseudo-tables
Tables in INFORMATION_SCHEMA
INNODB_TRX
INNODB_LOCKS
INNODB_LOCK_WAITS
INNODB_METRICS
Options innodb_monitor_*
Option innodb_print_all_deadlocks
Events
Waits
Mutexes
Statements
Stages
Memory
Replication
5.7+
Diagnosting locks
Summary
Table-level locks
P_S.TABLE_HANDLES
5.7+
Row-level locks
Tables in INFORMATION_SCHEMA
Option --innodb_print_all_deadlocks
MDL locks
P_S.METADATA_LOCKS
5.7+
MySQL Cluster
Special storage engine: NDB
Stores data on two or more physical machines
Two or more copies
General troubleshooting techniques
Applicable
MySQL Replication
Overview
Slave
IO thread read updates from master and stores in relay log file
Replication IO thread
Communication issues
Access error
P_S.replication_connection_status
Restart slave
Simple master-slave
How?
MySQL Utilities
mysqlrplsync, mysqldbcompare, mysqldiff
Lock issues
InnoDB
Triggers
Synchronize tables!
Different options
Threads
Seconds_behind_master is growing
Tune slave performance
Buffers
More information
OpenWorld sessions
October, 01
OpenWorld sessions
October, 02
Further reading
MySQL Troubleshooting book
http://shop.oreilly.com/product/0636920021964.do
http://marcalff.blogspot.ru/
Planet MySQL
http://planet.mysql.com/
http://dev.mysql.com/support/blogs/
http://mysqlserverteam.com/
References
MySQL User Reference Manual
http://dev.mysql.com/doc/refman/5.6/en/index.html
http://forums.mysql.com
Bug trackers
http://bugs.mysql.com
My Oracle Support
https://support.oracle.com
Thank you!