k8s部署的mysql出现报错Got an error writing communication packets

错误描述

请问各位大佬,最近在使用k8s部署mysql进行读写的时候,发现错误日志有出现如下报错:

Got an error reading communication packets

Got an error writing communication packets

Aborted connection 52628 to db: 'kangkang' user: 'root' host: '119.123.49.227' (Got an error reading communication packets)

实际情况如下

k8s部署的mysql出现报错Got an error writing communication packets

寻找解决方法

然后我去网上寻找相关解决办法,有找到以下方法:

一:修改max_allowed_packet

# 设置最大包大小
set global max_allowed_packet = 1024*1024*1024;
# 查看包大小
show variables like '%max_allowed_packet%';

二:检查Aborted connection

mysql> show global status like '%Aborted%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Aborted_clients  | 15    |
| Aborted_connects | 23737 |
+------------------+-------+
2 rows in set (18.99 sec)

其中Aborted_clients
The number of connections that were aborted because the client died without closing the connection properly.
由于客户端未正确关闭连接而死亡的连接数。

Aborted_connects
The number of failed attempts to connect to the MySQL server.
连接MySQL服务器失败的次数。

思路:

可能我在客户端进行写入操作的时候,还没得到结果就关闭连接,导致Aborted connection,
但是我的写入操作确实成功;

然后我尝试修改node.js的代码

router.get('/me', function (req, res) {
   function insertDb(){
     pool.getConnection(async (err,connection)=>{
      if (err) {
        throw err;
      }
      var user = {
        NAME: '隆隆',
        age: 17,
        pos: 'ope',
      };
      #等待写入完成
      await connection.query(`INSERT INTO staffs SET ?`, [user], (err, result) => {
        //如果有错误,抛出异常
        if (err) {
          console.log('查询失败');
          throw err;
        }
        //如果正常,开始查询
        console.log('正在插入数据');
        console.log(result);
        res.send(JSON.stringify(result));

      })
      #写入完成再关闭数据库连接
      connection.release();
    })
  }
  insertDb();
})

结果:

正在插入数据
OkPacket {
  fieldCount: 0,
  affectedRows: 1,
  insertId: 20,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0
}

显示的是成功,客户端没有报错;
但是,服务端的错误日志却照常打印,

2021-04-27T03:48:47.545011Z 58366 [Note] Aborted connection 58366 to db: 'kangkang' user: 'root' host: '***.123.49.***' (Got an error reading communication packets)
2021-04-27T03:48:50.896244Z 58537 [Note] Got an error writing communication packets
2021-04-27T03:51:32.124178Z 58620 [Note] Aborted connection 58620 to db: 'kangkang' user: 'root' host: '***.123.49.***' (Got an error reading communication packets)

问题:

客户端的mysql写入操作没有异常,结果也返回正确,但是服务端的mysql的错误日志为什么还是在报错呢?

感谢大佬们看到这里,如果你有解决思路或者解决方案,可以指点一二吗?谢谢大佬!

讨论数量: 1
2年前 评论
kangkanglaile (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!