排查环境
Server version: 5.7.26-29-log Percona Server (GPL)
问题描述
数据库周期性新增几条`unauthenticated user`的连接,连接长期未释放导致异常。
排查方法
## 查看用户为unauthenticated user的PROCESS
SELECT * FROM information_schema.processlist WHERE USER='unauthenticated user' LIMIT 1 \G
*************************** 1. row ***************************
ID: 127670873
USER: unauthenticated user
HOST: connecting host
DB: NULL
COMMAND: Connect
TIME: 965
STATE: login
INFO: NULL
TIME_MS: 965150
ROWS_SENT: 0
ROWS_EXAMINED: 0
1 row in set (0.01 sec)
## 根据PROCESSLIST_ID查找对应的处理进程
SELECT * FROM performance_schema.threads WHERE PROCESSLIST_ID=127670873 \G
*************************** 1. row ***************************
THREAD_ID: 127670969
NAME: thread/sql/one_connection
TYPE: FOREGROUND
PROCESSLIST_ID: 127670873
PROCESSLIST_USER: NULL
PROCESSLIST_HOST: NULL
PROCESSLIST_DB: NULL
PROCESSLIST_COMMAND: Sleep
PROCESSLIST_TIME: NULL
PROCESSLIST_STATE: NULL
PROCESSLIST_INFO: NULL
PARENT_THREAD_ID: NULL
ROLE: NULL
INSTRUMENTED: YES
HISTORY: YES
CONNECTION_TYPE: NULL
THREAD_OS_ID: 10039
1 row in set (0.00 sec)
## 根据THREAD_ID查找对应的连接信息
SELECT * FROM performance_schema.socket_instances WHERE `THREAD_ID`=127670969 \G
*************************** 1. row ***************************
EVENT_NAME: wait/io/socket/sql/client_connection
OBJECT_INSTANCE_BEGIN: 61360640
THREAD_ID: 127670969
SOCKET_ID: 200
IP: xxx.xxx.xxx.xxx
PORT: 59950
STATE: ACTIVE
1 row in set (0.00 sec)
## 如果是正常请求,可以通过PROCESSLIST_ID查找到请求应用信息
SELECT * FROM `performance_schema`.`session_connect_attrs` WHERE PROCESSLIST_ID=128200353;
+----------------+-----------------+---------------------------------------------+------------------+
| PROCESSLIST_ID | ATTR_NAME | ATTR_VALUE | ORDINAL_POSITION |
+----------------+-----------------+---------------------------------------------+------------------+
| 128200353 | _client_name | pymysql | 0 |
| 128200353 | _pid | 70794 | 1 |
| 128200353 | program_name | /xxx/xxxx.py | 2 |
| 128200353 | _client_version | 0.9.2 | 3 |
+----------------+-----------------+---------------------------------------------+------------------+
4 rows in set (0.00 sec)