MySQL挂在大桌子上,现在需要很长时间才能连接

时间:2017-02-01 01:26:21

标签: mysql

MySql在尝试删除包含5000万条记录的大表后,接受连接并且昏昏欲睡。以前的连接,现在需要20-30秒才能连接。

运行mysqlcheck会使表格正常,但SHOW ENGINE INNODB STATUS看起来不正确:

它开头有很多方面:

+--------+------+--------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------

对于许多行继续这样做,然后:

----------------------------------------------+
| InnoDB |      |
=====================================
2017-01-31 19:03:05 0x7f2be82e5700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 35 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 19 srv_active, 0 srv_shutdown, 1234 srv_idle
srv_master_thread log flush and writes: 1253
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 91
OS WAIT ARRAY INFO: signal count 74
RW-shared spins 0, rounds 58, OS waits 23
RW-excl spins 0, rounds 205, OS waits 0
RW-sx spins 0, rounds 0, OS waits 0
Spin rounds per wait: 58.00 RW-shared, 205.00 RW-excl, 0.00 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 40192594
Purge done for trx's n:o < 40190602 undo n:o < 0 state: running but idle
History list length 2280
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421306474252112, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
 ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
369979 OS file reads, 61 OS file writes, 15 OS fsyncs
286.85 reads/s, 16384 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 2193, seg size 2195, 0 merges
merged operations:
 insert 0, delete mark 0, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 1182691, node heap has 0 buffer(s)
Hash table size 1182691, node heap has 3 buffer(s)
Hash table size 1182691, node heap has 3 buffer(s)
Hash table size 1182691, node heap has 6 buffer(s)
Hash table size 1182691, node heap has 2 buffer(s)
Hash table size 1182691, node heap has 2 buffer(s)
Hash table size 1182691, node heap has 1 buffer(s)
Hash table size 1182691, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 310536690314
Log flushed up to   310536690314
Pages flushed up to 310536690314
Last checkpoint at  310536690305
0 pending log flushes, 0 pending chkp writes
16 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 4397727744
Dictionary memory allocated 39828543
Buffer pool size   262112
Free buffers       0
Database pages     262095
Old database pages 96806
Modified db pages  0
Pending reads      1
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 103, not young 6145557
0.00 youngs/s, 92166.80 non-youngs/s
Pages read 369591, created 34, written 37
286.88 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 368 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 262095, unzip_LRU len: 0
I/O sum[120336]:cur[304], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size   32764
Free buffers       0
Database pages     32761
Old database pages 12102
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 12, not young 782981
0.00 youngs/s, 12008.66 non-youngs/s
Pages read 46266, created 0, written 3
36.46 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 369 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32761, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size   32764
Free buffers       0
Database pages     32760
Old database pages 12090
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 23, not young 714985
0.00 youngs/s, 10882.83 non-youngs/s
Pages read 43701, created 0, written 0
33.54 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 361 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32760, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 2
Buffer pool size   32764
Free buffers       0
Database pages     32762
Old database pages 12102
Modified db pages  0
Pending reads      1
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 12, not young 826273
0.00 youngs/s, 12544.36 non-youngs/s
Pages read 47653, created 0, written 0
40.11 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 363 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32762, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 3
Buffer pool size   32764
Free buffers       0
Database pages     32763
Old database pages 12103
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 11, not young 789399
0.00 youngs/s, 10819.38 non-youngs/s
Pages read 46867, created 0, written 0
34.46 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 364 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32763, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 4
Buffer pool size   32764
Free buffers       0
Database pages     32762
Old database pages 12089
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 24, not young 716775
0.00 youngs/s, 10601.24 non-youngs/s
Pages read 45316, created 0, written 0
32.43 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 371 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32762, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 5
Buffer pool size   32764
Free buffers       0
Database pages     32762
Old database pages 12094
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 20, not young 816196
0.00 youngs/s, 12974.26 non-youngs/s
Pages read 47369, created 0, written 0
39.77 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 378 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32762, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 6
Buffer pool size   32764
Free buffers       0
Database pages     32764
Old database pages 12113
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 1, not young 739215
0.00 youngs/s, 11328.79 non-youngs/s
Pages read 46339, created 34, written 34
34.51 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 373 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32764, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
---BUFFER POOL 7
Buffer pool size   32764
Free buffers       0
Database pages     32761
Old database pages 12113
Modified db pages  0
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 759733
0.00 youngs/s, 11007.29 non-youngs/s
Pages read 46080, created 0, written 0
35.60 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 999 / 1000, young-making rate 0 / 1000 not 367 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32761, unzip_LRU len: 0
I/O sum[15042]:cur[38], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Process ID=2785, Main thread ID=139826948695808, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 14
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
+--------+------+---------------------------------------------------------------
                                                                                           --------------------------------------------------------------------------------                                                                                                --------------------------------------------------------------------------------                                                                                                --------------------------------------------------------------------------------                                                                                                -------------------------------------------------------------------------------- 

最后,输出在开始时以多行破折号结束。

请告知我有关排除故障和修复的其他步骤。

2 个答案:

答案 0 :(得分:1)

如果您怀疑innoDB的行为异常,您可以查看引擎正在做什么,这很昂贵,所以在正常情况下不要这样做。手册说明如下:

  

启用InnoDB监视器以获取有关问题的信息(请参阅   第14.17节“InnoDB监视器”)。如果问题是   性能相关,或者你的服务器似乎挂了,你应该   启用标准监视器以打印有关内部的信息   InnoDB的状态。如果问题出在锁定上,请启用锁定   监控。如果问题在于创建表或其他数据   字典操作,使表监视器能够打印内容   InnoDB内部数据字典。查看表空间信息   启用表空间监视器。

     

InnoDB暂时启用标准的InnoDB Monitor输出   以下条件:

     
      
  • 长信号量等待

  •   
  • InnoDB无法在缓冲池中找到空闲块

  •   
  • 超过67%的缓冲池被锁堆或自适应哈希索引占用

  •   

https://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html https://dev.mysql.com/doc/refman/5.6/en/innodb-monitors.html

答案 1 :(得分:0)

毕竟,问题的巧合和大表丢弃问题不是原因。这是网络上的DNS问题。

skip-name-resolve添加到/etc/my.cnf(我的系统是CentOS)并重新启动服务器后,连接似乎恢复正常。

[mysqld]
skip-name-resolve