mysql 5.6新機能解説@第一回 中国地方db勉強会
TRANSCRIPT
Technical Polygon
MySQL 5.6
@nippondanjimikiya (dot) okuno (at) gmail (dot) com
DB
MySQL2000
2007MySQL KK
13
MySQL
Q&A
GNU
KDE
http://nippondanji.blogspot.com/
MySQL
11
API
API
GNU BisonLexical Scanner
2
C/C++100
MySQL
MySQLAPIJavaMyISAM
table_name.MYItable_name.MYDInnoDBMySQLCluster NDBAPIPHPODBC
SQL
MySQL 5.6!!
20132
MySQL 5.5GA12
3.234.04.15.05.15.5
MySQL
1979: MySQLBASICC
1985: Michael WideniusTCX DataKonsult
1990: SQL
1995: MySQL 1.0
SQL
Solaris
1996: 3.11Linux
2000: 3.23
UnderstandingMySQLInternals
MySQL 3.232000
ISAMMyISAM
Berkeley DB
MySQL 4.02003InnoDB
UNION
SSL
MySQL 4.12004Unicode
MySQL 5.02005
XA
Information schema
MySQL 5.12008
XML
MySQL 5.52010
InnoDB Plugin
4UTF-8
FLUSH LOGS
COLUMNS
DTrace
Performance schema
MySQL 5.6!!
GTID Global Transaction ID
mysqlbinlog
NIC
SQL
DB
InnoDB
FULLTEXT
.ibd
16KB4KB/8KB/16KB
START TRANSACTION READ ONLY
4GB512GB
CPU
memcached
semi-join
FROM
EXPLAINSELECTDML
JSONMySQL WorkbenchVisual Explain
ORDER BY ... LIMIT
Batched Key Access Join
Index Condition Pushdown
Multi Range Read
10248192
OpenGIS
Diagnostic Area
Performance SchemaON
MySQL 5.6http://nippondanji.blogspot.com/2012/10/mysql-56.html
MySQL 5.6
RDBMS
MySQL
I/OSQL
1. COMMIT
2.
3.
4-1. send_ok
4-2.
5.
6.
MySQL
MasterSlave
/
MasterSlaveSlaveSlave
1:N
Master+ SlaveMaster+ Slave
Master+ SlaveMaster+ SlaveMaster+ Slave
MasterSlave
Slave
MySQL 5.5
I/OSQL
1. COMMIT
2.
3.
7. send_ok
4.
5.
6-2.
6-1-1. ack
6-1-2. ack
COMMIT
HA
HA
1:1
1:N
Global Transaction ID
IDUUID:ID
095E0FF8-18AF-11E2-9E7C-5C260A2AA986:123456
ID1:N
MASTER_AUTO_POSITION = 1
Global Transaction ID
mysql> show binlog events in 'mysql-bin.000002'\G
*************************** 3. row *************************** Log_name: mysql-bin.000002 Pos: 151 Event_type: Gtid Server_id: 1End_log_pos: 199 Info: SET @@SESSION.GTID_NEXT= '095E0FF8-18AF-11E2-9E7C-5C260A2AA986:1'
Global Transaction ID
mysql> SHOW SLAVE STATUS\G*************************** 1. row *************************** Master_UUID: 095e0ff8-18af-11e2-9e7c-5c260a2aa986 Master_Info_File: /path/to/datadir/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 095E0FF8-18AF-11E2-9E7C-5C260A2AA986:1 Executed_Gtid_Set: 095E0FF8-18AF-11E2-9E7C-5C260A2AA986:11 row in set (0.00 sec)
-
SHOW BINLOG EVENTS
mysql> change master to master_host='127.0.0.1', -> master_port=13032, -> master_user = 'rsandbox', -> master_password = 'rsandbox', -> master_log_file = 'mysql-bin.123456', -> master_log_pos = 123456;Query OK, 0 rows affected (0.00 sec)
mysql> start slave;Query OK, 0 rows affected (0.00 sec)
-
mysql> change master to master_host='127.0.0.1', -> master_port=13032, -> master_auto_position = 1;Query OK, 0 rows affected (0.03 sec)
mysql> start slave user='rsandbox' password='rsandbox';Query OK, 0 rows affected, 1 warning (0.00 sec)
mysqlfailover
MySQL WorkbenchMySQL Utilities
Python
mysqlfailover
shell> mysqlfailover --master=root:[email protected]:13032 \ --slaves=root:[email protected]:13033,root:[email protected]:13034
MySQL Replication Failover UtilityFailover Mode = auto Next Interval = Thu Oct 18 22:42:14 2012
Master Information------------------Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB mysql-bin.000006 191
Replication Health Status+------------+--------+---------+--------+------------+---------+| host | port | role | state | gtid_mode | health |+------------+--------+---------+--------+------------+---------+| 127.0.0.1 | 13032 | MASTER | UP | ON | OK || 127.0.0.1 | 13033 | SLAVE | UP | ON | OK || 127.0.0.1 | 13034 | SLAVE | UP | ON | OK |+------------+--------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
mysqlfailover
MySQL Replication Failover UtilityFailover Mode = auto Next Interval = Thu Oct 18 22:43:31 2012
Master Information------------------Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB mysql-bin.000003 621
Replication Health Status+------------+--------+---------+--------+------------+---------+| host | port | role | state | gtid_mode | health |+------------+--------+---------+--------+------------+---------+| 127.0.0.1 | 13033 | MASTER | UP | ON | OK || 127.0.0.1 | 13034 | SLAVE | UP | ON | OK |+------------+--------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
server_id=1log_bin=mysql-bin
gtid_mode=onlog_slave_updatesdisable_gtid_unsafe_statementsmaster_info_repository=TABLErelay_log_info_repository=TABLErelay_log_recovery=1report_host=hostnamereport_port=3306
MySQL 5.6
InnoDBrelay_log_info
InnoDB
InnoDB
mysql.slave_relay_log_info
server_id=1log_bin=mysql-bin
gtid_mode=onlog_slave_updatesdisable_gtid_unsafe_statementsmaster_info_repository=TABLErelay_log_info_repository=TABLErelay_log_recovery=1report_host=hostnamereport_port=3306
CRC32
binlog_checksum=CRC32
master_verify_checksum=1
slave_sql_verify_checksum=1
InnoDB
DDL
MySQL 5.1
ALTER TABLE
ALTER
MySQL 5.1 InnoDB Plugin5.5
MySQL 5.6 New
/
.ibdinnodb_file_per_table
MySQL 5.5
MySQL 5.6FLUSH TABLES t FOR EXPORT
/
FLUSH TABLES t FOR EXPORT;
.ibd.cfg
UNLOCK TABLES;
CREATE TABLE t () ENGINE INNODB;
ALTER TABLE t DISCARD TABLESPACE;
.ibd.cfg
ALTER TABLE t IMPORT TABLESPACE;
innodb_print_all_deadlocks
InnoDB: transactions deadlock detected, dumping detailed information.121018 2:28:28*** (1) TRANSACTION:TRANSACTION 6426, ACTIVE 16 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 376, 2 row lock(s), undo log entries 1MySQL thread id 1, OS thread handle 0x7f126453c700, query id 53 localhost msandbox updatingupdate t set b='sss' where a=1*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 6 page no 3 n bits 72 index `PRIMARY` of table `test`.`t` trx id 6426 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0 0: len 4; hex 00000001; asc ;; 1: len 6; hex 000000001917; asc ;; 2: len 7; hex 13000001890110; asc ;; 3: len 3; hex 747474; asc ttt;;
*** (2) TRANSACTION:TRANSACTION 6423, ACTIVE 65 sec starting index read
*** WE ROLL BACK TRANSACTION (2)
CPU
MySQL ConnectR/W sysbench MySQL 5.5151%
Read Only sysbench MySQL 5.5234%
http://medianetwork.oracle.com/video/player/1873154739001
kernel_mutex
START TRANACTION READ ONLY
autocommit=1SELECT
Adaptive Flushinglow water markinnodb_adaptive_flushing_lwm
innodb_max_dirty_pages_pct_lwm
I/Oinnodb_io_capacity_max
innodb_flushing_avg_loops
pager_cleaner
innodb_lru_scan_depth
innodb_flush_neighbors
memcached
MySQLInnoDBSQLmemcachedMySQLMySQLMySQL
memcachedmemcached
3306
11211
MySQL 5.6
Disk Sweep Multi Range Read (MRR)
Batched Key Access Join (BKA)
Index Condition Pushdown (ICP)
ORDER BY LIMIT
Semi-Join
FROM
MRR
MRR
MRR
ROWIDROWIDROWID
MySQL 5.5
Nested Loop Join
SELECT FROM t1 JOIN t2 ON WHERE ...
for each row in t1 matching where condition { for each row in t2 matching join and where condition { send joined row to client }}
MySQL 5.5
Block Nested Loop Join
JOIN Buffer
t1
t2
1. WHEREt1
2. t2JOIN
3. t1
Using Join Buffer...
Batched Key Access Join
JOIN Buffer
t1
t2
1. WHEREt1
2. MRRt2JOIN
4. t1
MRRScan3. ROWIDt2
Index Condition Pushdown
(col1, col2, col3)WHERE col1=1 AND col3 SHOW STATUS LIKE 'handler_read%';+-----------------------+--------+| Variable_name | Value |+-----------------------+--------+| Handler_read_first | 240 || Handler_read_key | 240 || Handler_read_last | 0 || Handler_read_next | 239 || Handler_read_prev | 0 || Handler_read_rnd | 0 || Handler_read_rnd_next | 824291 |+-----------------------+--------+7 rows in set (0.00 sec)
MySQL 5.6 - EXPLAIN
EXPLAIN SELECT COUNT(1) FROM Country WHERE Country.Code IN (SELECT City.CountryCode FROM City WHERE Name LIKE 'A%')\G*************************** 1. row *************************** id: 1 select_type: SIMPLE table: Country type: indexpossible_keys: PRIMARY key: PRIMARY key_len: 3 ref: NULL rows: 239 Extra: Using where; Using index*************************** 2. row *************************** id: 1 select_type: SIMPLE table: type: eq_refpossible_keys: key: key_len: 3 ref: world.Country.Code rows: 1 Extra: NULL
MySQL 5.6 - EXPLAIN
*************************** 3. row *************************** id: 2 select_type: MATERIALIZED table: City type: ALLpossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4188 Extra: Using where3 rows in set (0.00 sec)
MySQL 5.6 - SELECT
mysql> SELECT COUNT(1) FROM Country WHERE Country.Code IN (SELECT City.CountryCode FROM City WHERE Name LIKE 'A%')\G*************************** 1. row ***************************COUNT(1): 711 row in set (0.00 sec)
mysql> SHOW STATUS LIKE 'handler_read%';+-----------------------+-------+| Variable_name | Value |+-----------------------+-------+| Handler_read_first | 2 || Handler_read_key | 241 || Handler_read_last | 0 || Handler_read_next | 239 || Handler_read_prev | 0 || Handler_read_rnd | 0 || Handler_read_rnd_next | 4080 |+-----------------------+-------+7 rows in set (0.00 sec)
FROM
EXPLAIN
WHERE
MySQL 5.5
mysql> SELECT COUNT(1) FROM Country C1 JOIN (SELECT * FROM City) AS C2 ON (C1.Capital = C2.ID) WHERE C1.Name LIKE 'X%';+----------+| COUNT(1) |+----------+| 0 |+----------+1 row in set (0.00 sec)
mysql> SHOW STATUS LIKE 'handler_read%';+-----------------------+-------+| Variable_name | Value |+-----------------------+-------+| Handler_read_first | 2 || Handler_read_key | 2 || Handler_read_last | 0 || Handler_read_next | 0 || Handler_read_prev | 0 || Handler_read_rnd | 0 || Handler_read_rnd_next | 4320 |+-----------------------+-------+7 rows in set (0.00 sec)
MySQL 5.6
mysql> SELECT COUNT(1) FROM Country C1 JOIN (SELECT * FROM City) AS C2 ON (C1.Capital = C2.ID) WHERE C1.Name LIKE 'X%';+----------+| COUNT(1) |+----------+| 0 |+----------+1 row in set (0.00 sec)
mysql> SHOW STATUS LIKE 'handler_read%';+-----------------------+-------+| Variable_name | Value |+-----------------------+-------+| Handler_read_first | 1 || Handler_read_key | 1 || Handler_read_last | 0 || Handler_read_next | 0 || Handler_read_prev | 0 || Handler_read_rnd | 0 || Handler_read_rnd_next | 240 |+-----------------------+-------+7 rows in set (0.00 sec)
MySQL 5.6
InnoDB
MySQL
Click to edit the title text format