0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQL(Amazon Lunux 2)のパケットの最大サイズを変更する

Last updated at Posted at 2022-03-03

初めに

Amazon Lunux 2 + MySQL + Sequelizeを使用して、画像をINSERTする際に以下のエラーが出力された。
MySQLのパケットの最大サイズを変更することよって解決できたため、その方法を記載する。

Unhandled rejection Error: SequelizeDatabaseError: ER_NET_PACKET_TOO_LARGE: Got a packet bigger than 'max_allowed_packet' bytes

環境

■ 使用OS
Amazon Lunux 2
■ MySQLバージョン
5.7.35
■ Sequelizeバージョン
3.30.4
■ データベース管理ツール
MySQL Workbench

解決方法

MySQLの設定ファイルを編集する。

# vim /etc/my.cnf

[mysqld]
max_allowed_packet=52MB

max_allowed_packetという変数に任意のバイト数を格納する。
今回は52MBまでのパケットを許容する設定にする。
※アプリの仕様上必要な値が52MBだったため今回は上記の設定だが、バイト数は任意で変更する。

MySQL 5.6 Server およびクライアント間で転送可能なパケットの最大サイズは 1G バイトです。

MySQLの公式によると最大サイズは 1G バイトとある。

MySQLを再起動する。

# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

Workbenchにて以下のコマンドを入力して結果を確認。

show variables like 'max_allowed_packet';

SnapCrab_NoName_2022-3-1_12-28-5_No-00.png

上記で変更可能である。

Dockerの場合

mysql:5.7を使用している場合は下記のファイルを変更する。

/etc/mysql/mysql.conf.d/mysqld.cnf

上記と同じように記載を行い、再起動すれば設定が反映される。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?