今天在測試環境發生了貌似怪異的報錯,
表結構如下:
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了,懷疑是規格太小導緻,等更新下執行個體規格看看