经过案例分析MySQL中使人头疼的Aborted告警

经过案例分析MySQL中使人头疼的Aborted告警

转载  2017-06-29   做者:dbapower   我要评论mysql

这篇文章经过案例跟你们分析了MySQL中使人头疼的Aborted告警的相关资料,文中将Aborted告警介绍的很是详细,对你们具备必定的参考学习价值,须要的朋友们下面来一块儿看看吧。sql

 

 

本文主要给你们介绍的是关于MySQL中Aborted告警的相关内容,分享出来供你们参考学习,下面来一块儿看看详细的介绍:数据库

实战编程

Part1:写在最前服务器

在MySQL的error log中,咱们会常常性看到一些各种的Aborted connection错误,本文中会针对这类错误进行一个初步分析,并了解一个问题产生后的基本排查思路和方法。掌握这种方法是相当重要的,而不是出现问题了,去猜,去试。数据库出现问题的时候须要DBA在短期内快速解决问题,所以一个好与坏的DBA,区别也在于此。编程语言

Part2:种类工具

?学习

1spa

2日志

3

4

5

6

[Warning] Aborted connection 305628 to db: 'db' user: 'dbuser' host: 'hostname' (Got an error reading communication packets)

[Warning] Aborted connection 81 to db:'unconnected' user: 'root' host: '127.0.0.1' (Got timeout reading communication

packets)

[Warning] Aborted connection 109 to db:'helei1' user: 'sys_admin' host: '192.168.1.1' (Got an error writing communication packets)

[Warning] Access denied for user 'root'@'127.0.0.1' (using password: YES)

[Warning] Got an error writing communication packets

Part3:重点参数分析

wait_timeout

 

Command-Line Format --wait-timeout=#
System Variable Name wait_timeout
Variable Scope Global, Session
Dynamic Variable Yes
Permitted Values (Windows) Type integer
Default 28800
Min Value 1
Max Value 2147483
Permitted Values (Other) Type integer
Default 28800
Min Value 1
Max Value 31536000

 

这个参数指的是数据库系统在关闭它以前,服务器等待非交互式链接上的活动的秒数。

interactive_timeout

 

Command-Line Format --interactive-timeout=#
System Variable Name interactive_timeout
Variable Scope Global, Session
Dynamic Variable Yes
Permitted Values Type integer
Default 28800
Min Value 1

 

这个参数指的是在关闭交互式链接以前,服务器等待活动的秒数

Warning:警告这两个参数建议一块儿调节,可以避免一些坑。

本文的两个参数值采用的是默认值

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

mysql> show global variables like '%timeout%';

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

| Variable_name    | Value |

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

| connect_timeout   | 10  |

| delayed_insert_timeout  | 300  |

| innodb_lock_wait_timeout | 50  |

| innodb_rollback_on_timeout | OFF  |

|interactive_timeout  | 28800 |

| lock_wait_timeout   | 31536000 |

| net_read_timeout   | 30  |

| net_write_timeout   | 60  |

| slave_net_timeout   | 3600  |

|wait_timeout    | 28800 |

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

10 rows in set (0.01 sec)

另外在数据库中,咱们重点关注下这两个参数,看看什么状况下Aborted_clients会提高,什么状况下Aborted_connects 会提高

?

1

2

3

4

5

6

7

8

mysql>show global status like 'aborted%';

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

|Variable_name | Value |

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

|Aborted_clients | 19 |

|Aborted_connects | 0  |

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

2 rows inset (0.00 sec)

Part4:案例1

这里我故意输入错误的密码5次,来看下数据库的error log和Aborted的哪一个参数记载了这一问题

?

1

2

3

4

5

6

7

8

9

10

[root@HE3~]# mysql -uroot -pwrongpass -h127.0.0.1

ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

[root@HE3~]# mysql -uroot -pwrongpass -h127.0.0.1

ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

[root@HE3~]# mysql -uroot -pwrongpass -h127.0.0.1

ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

[root@HE3~]# mysql -uroot -pwrongpass -h127.0.0.1

ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

[root@HE3~]# mysql -uroot -pwrongpass -h127.0.0.1

ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)

能够看出,这里的Aborted_connects 记录了密码错误的这一问题

?

1

2

3

4

5

6

7

8

mysql>show global status like 'aborted%';

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

|Variable_name | Value |

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

|Aborted_clients | 19 |

|Aborted_connects | 5  |

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

2 rows inset (0.00 sec)

error log中,也记载了这类密码输错的信息

?

1

2

3

4

5

[Warning] Access denied for user'root'@'127.0.0.1' (using password: YES)

[Warning] Access denied for user 'root'@'127.0.0.1' (using password:YES)

[Warning] Access denied for user 'root'@'127.0.0.1' (using password:YES)

[Warning] Access denied for user 'root'@'127.0.0.1' (using password:YES)

[Warning] Access denied for user 'root'@'127.0.0.1' (using password:YES)

Part5:案例2

接下来咱们看下文章第三节提到的两个重点参数对数据库链接的行为影响

这里咱们将这两个参数均配置为10秒

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

mysql>set global wait_timeout=10;

Query OK,0 rows affected (0.00 sec)

   

mysql>set global interactive_timeout=10;

Query OK,0 rows affected (0.00 sec)

mysql>show processlist;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect... Connection id: 79 Current database: *** NONE ***

   

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

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

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

| 79 |root | 127.0.0.1:42016 | NULL | Query | 0 | NULL | show processlist |

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

1 row in set (0.00 sec)

这里三次操做,能够看到clients数上升,这是因为timeout参数控制的,已经链接上数据的链接被杀掉。

?

1

2

3

4

5

6

7

8

9

10

11

mysql>show global status like 'aborted%';

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect... Connection id: 81 Current database: *** NONE ***

   

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

|Variable_name | Value |

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

|Aborted_clients | 22 |

|Aborted_connects | 5  |

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

2 rows in set (0.01 sec)

error log中记载的是

?

1

2

3

[Warning] Aborted connection 81 to db: 'unconnected' user: 'root' host: '127.0.0.1' (Got timeout reading communication packets)

[Warning] Aborted connection 78 to db: 'unconnected' user: 'root' host: '127.0.0.1' (Got timeout reading communication packets) 

[Warning] Aborted connection 79 to db: 'unconnected' user: 'root' host: '127.0.0.1' (Got timeout reading communication packets)

Part6:案例3

在这个案例中咱们看下最大链接数对数据库链接的行为影响

?

1

2

3

4

5

6

7

8

9

10

11

12

mysql>show global variables like 'max_conn%';

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

|Variable_name  | Value |

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

|max_connect_errors | 1000 |

|max_connections | 1024 |

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

2 rows in set (0.00 sec)

   

   

mysql>set global max_connections=2;

Query OK,0 rows affected (0.00 sec)

这里看到爆出了链接数过多的问题

?

1

2

[root@HE3~]# mysql -uroot -pMANAGER -h127.0.0.1

ERROR 1040 (HY000): Too many connections

而错误日志没有任何记录

Part7:案例4

第三方工具navicat select结果没有出来的时候选择中止则出现

clients上涨

?

1

2

3

4

5

6

7

8

mysql>show global status like 'aborted%';

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

|Variable_name | Value |

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

|Aborted_clients | 28 |

|Aborted_connects | 10 |

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

2 rows in set (0.00 sec)

error log日志记录

?

1

170626 16:26:56 [Warning] Aborted connection 109 to db: 'helei1' user: 'sys_admin' host: '192.168.1.1' (Got an error writing communication packets)

Part8:缘由总结

  1. 在MySQL中sleep状态数百秒的并且常常重复链接是应用程序在工做后没有关闭链接的症状之一,而是依靠数据库wait_timeout来关闭它们。强烈建议在操做结束时更改应用程序逻辑以正确关闭链接;
  2. 检查以确保max_allowed_packet的值足够高,而且客户端没有收到“数据包太大”消息。 这种状况他会停止链接,而不正确关闭它;
  3. 另外一种可能性是TIME_WAIT。建议您确认链接被妥善管理而且是在应用端正常关闭;
  4. 确保事务正确提交(开始和提交),以便一旦应用程序“完成”链接,它将处于“clean”的状态;
  5. 您应该确保客户端应用程序不停止链接。 例如,若是PHP的选项max_execution_time设置为5秒,增长connect_timeout是没用的,由于PHP会杀死脚本。 其余编程语言和环境也有相似的选项;
  6. 链接延迟的另外一个缘由是DNS问题。 检查是否启用了skip-name-resolve,检查主机根据其IP地址而不是其主机名进行身份验证;
  7. 尝试增长MySQL的net_read_timeout和net_write_timeout值,看看是否减小了错误的数量。

总结

经过这4个案例,咱们可以了解到,Aborted_clients、和Aborted_connects的区别,以及什么状况下会爆出什么样的错误日志,文章第二节中的几个Aborted错误是常见的错误,这类错误出现的时候脑海里要有一个理论知识,知道什么状况下,会出现什么样的错误,以便快速定位问题。因为笔者的水平有限,编写时间也很仓促,文中不免会出现一些错误或者不许确的地方,不妥之处恳请读者批评指正。

好了,以上就是这篇文章的所有内容了,但愿本文的内容对你们的学习或者工做能带来必定的帮助,若是有疑问你们能够留言交流,谢谢你们对脚本之家的支持。

相关文章
相关标签/搜索