ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes

今天在测试环境发生了貌似怪异的报错,
表结构如下:

CREATE TABLE `test` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `step` bigint(20) NOT NULL COMMENT 'step',
  `data` longtext COMMENT 'step data',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1778606 DEFAULT CHARSET=utf8 COMMENT='test'

要查询一条数据

select char_length(data) from test where id=1;

结果却是:

mysql> ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes

而实际情况是:

mysql> select length(data),char_length(data) from test where id=1;
+--------------+-------------------+
| length(data) | char_length(data) |
+--------------+-------------------+
|     22270339 |          22270339 |
+--------------+-------------------+
1 row in set (0.12 sec)

为什么已经把max_allowed_packet设置成最大了,还是报ERROR 2020 (HY000)错啊?

mysql> show global variables like "max_allowed_packet";
+--------------------+------------+
| Variable_name      | Value      |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+
1 row in set (0.00 sec)

即使里面存的中文utf8占3个字节,22270339*3<1073741824啊,忽然灵机一动,看了

mysql> show global variables like "innodb_buffer_pool_size";
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| innodb_buffer_pool_size | 880803840 |
+-------------------------+-----------+
1 row in set (0.00 sec)

mysql> select 880803840/(1024*1024*1024.0);                                                                                                                                               +------------------------------+
| 880803840/(1024*1024*1024.0) |
+------------------------------+
|                       0.8203 |
+------------------------------+
1 row in set (0.00 sec)

max_allowed_packet已经大于innodb_buffer_pool_size了,怀疑是规格太小导致,等升级下实例规格看看

点赞