Application was streaming results when the connection failed. Consider raising value of 'net_write_timeout' on the server.

鬼谷子叔叔 - 2025-09-11 15:31

问题

在使用JDBC连接MySQL数据库读取大量数据的时候会遇到JDBC报如下错误:

Application was streaming results when the connection failed. Consider raising value of 'net_write_timeout' on the server.

原因

这是因为JDBC在使用stream读取数据的时候会有一个超时时间,达到超时时间就会报这个错误。

解决

单纯地改MySQL的net_write_timeout是不能解决问题的!!!

设置MySQL的net超时时间:

set global net_read_timeout = 7200;
set global net_rewrite_timeout = 7200;
set global net_retry_count = 100;

设置JDBC的net超时参数:

&autoReconnect=true&netTimeoutForStreamingResults=7200