您的位置:首页 > 数据库 > MySQL

msyql优化案例

2016-06-08 17:55 381 查看
同事反馈系统的sql执行的很慢,当时的第一想法是去查看慢日志,然而慢日志中什么也没有,当时在纠结是不是记录慢sql出现了问题,浪费了写时间,然后想到了如果是出现了锁等待,那么sql会一直无法执行,而如果实际执行的时间很短的话,是不会记录到慢日志中的,于是去查看了下锁等待的情况,果然是有等待发生:

select * from innodb_lock_waits;

+——————-+———————-+—————–+———————-+

| requesting_trx_id | requested_lock_id | blocking_trx_id | blocking_lock_id |

+——————-+———————-+—————–+———————-+

| 5650306 | 5650306:11995:9:2 | 5650302 | 5650302:11995:9:2 |

| 5650306 | 5650306:11995:9:2 | 5649077 | 5649077:11995:9:2 |

| 5650302 | 5650302:11995:9:2 | 5649077 | 5649077:11995:9:2 |

| 5650287 | 5650287:11797:22:24 | 5649077 | 5649077:11797:22:24 |

| 5650284 | 5650284:11828:189:10 | 5649077 | 5649077:11828:189:10 |

+——————-+———————-+—————–+———————-+

看到都是被5649077阻塞住了,去查看下9077事务在干什么

[b]*****************[/b] 4. row [b]*****************[/b]

trx_id: 5649077

trx_state: RUNNING

trx_started: 2016-06-08 09:15:24

trx_requested_lock_id: NULL

trx_wait_started: NULL

trx_weight: 10109

trx_mysql_thread_id: 1468

trx_query: NULL

trx_operation_state: NULL

trx_tables_in_use: 0

trx_tables_locked: 0

trx_lock_structs: 3930

trx_lock_memory_bytes: 439848

trx_rows_locked: 185762

trx_rows_modified: 6179

trx_concurrency_tickets: 0

trx_isolation_level: REPEATABLE READ

trx_unique_checks: 1

trx_foreign_key_checks: 1

trx_last_foreign_key_error: NULL

trx_adaptive_hash_latched: 0

trx_adaptive_hash_timeout: 10000

trx_is_read_only: 0

trx_autocommit_non_locking: 0

什么也没干,对应的mysql thread id是1468,在看下1468是在干什么

+——+————–+———————-+——————–+————-+——+———————————————————————–+——————————————————————————————————+———-+

| Id | User | Host | db | Command | Time | State | Info | Progress |

+——+————–+———————-+——————–+————-+——+———————————————————————–+——————————————————————————————————+———-+

| 3 | rdsrepladmin | 172.25.0.249:56968 | NULL | Binlog Dump | 3582 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL | 0.000 |

| 5 | xxxx | localhost:26557 | NULL | Sleep | 13 | | NULL | 0.000 |

| 1468 | xxxxxxxx | 10.248.192.243:33895 | xxxxxxx | Sleep | 583 | | NULL | 0.000 |

线程也是什么都没干,mysql就有这样的问题,事务么有正常结束,锁就释放的不干净,很容易发生阻塞的现象。直接kill掉therad后,系统正常。

吐槽下,mysql还是很弱的。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql-优化