在mysql docker中增加max_allowed_pa​​cket大小

我们使用的是Docker for mysql,我们在运行时遇到以下错误

Packet for query is too large (12884616 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.; nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12884616 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable. 

现在我们需要在mysqlconfiguration中增加max_allowed_packet大小,任何人都可以通过docker命令来增加max_allowed_packet

作为容器命令的一个参数:

 docker run -it -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7 --max-allowed-packet=67108864 

请参阅https://hub.docker.com/_/mysql/上的 “没有cnf文件的configuration”,在这里复制后面的内容:

没有cnf文件的configuration许多configuration选项可以作为标志传递给mysqld。 这将使您能够灵活地自定义容器而不需要cnf文件。 例如,如果要更改所有表的默认编码和归类以使用UTF-8(utf8mb4),请运行以下命令:

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

如果您想查看可用选项的完整列表,请运行:

$ docker run -it --rm mysql:tag --verbose --help

我认为你应该像这样在你的Dockerfile中修改它:

RUN sed -ire 's/max_allowed_packet.*=.*/max_allowed_packet = YOURVALUE/g' /etc/mysql/my.cnf

Interesting Posts