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还是很弱的。。。。
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还是很弱的。。。。
相关文章推荐
- Navicat Premium 将sqlserver 数据库 导入mysql 中
- MySQL各版本的区别
- mysql表添加联合唯一索引
- mysql group by的用法 注意
- mysql高级排序&高级匹配查询示例
- MySQL无法存储Emoji表情问题
- MySQL 语句优化
- Mysql 5.7.12解压版的安装及配置系统编码
- MySQL 数据库还原语句
- mysql 多实例应用配置部署指南
- mysql命令行查看表结构,字段等信息
- 【mysql函数】FIND_IN_SET函数用法
- Mysql命令
- MySQL数据库优化(四)——MySQL索引优化
- mysql插入数据后返回自增ID
- mysql主从服务器
- MySQL去除重复数据
- 聚簇索引和非聚簇索引
- liunx下绿色版MySQL安装
- mysql校对规则(COLLATION)详解