在插入大blob时,mySQL断开连接。

时间:2022-09-23 08:43:35

I'm using this method to insert a large blob into my mySQL database (Blob size ~40MB) After ~15 seconds it throws a exception. The whole thing here works with blobs smaller then ~20MB.

我使用这个方法将一个大的blob插入到我的mySQL数据库中(blob大小~40MB),在15秒之后,它抛出一个异常。这里所有的东西都是和小点的小点一起工作的~20MB。

protected override int internalExecuteInt(string SQL, byte[] Blob)
{
    using (MySqlCommand cmd = new MySqlCommand(SQL, connection))
    {
        if (Blob != null)
        {
            cmd.CommandTimeout = 600;
            cmd.Parameters.AddWithValue("@blob", Blob);
        }
        return cmd.ExecuteNonQuery();
    }
}

...
internalExecuteInt("INSERT INTO images (image) VALUES (@blob)", myLargeBlob);
...

Exception:

例外:

MySqlException: Fatal error encountered during command execution.

MySqlException:在命令执行过程中遇到的致命错误。

Inner exception:

内心的例外:

SocketException: An existing connection was forcibly closed by the remote host

SocketException:一个现有的连接被远程主机强制关闭。

I have already changed net_read_timeout (600), net_write_timeout (600), wait_timeout (28800), slave_net_timeout (3600) and interactive_timeout (28800).

我已经更改了net_read_timeout(600)、net_write_timeout(600)、wait_timeout(28800)、slave_net_timeout(3600)和interactive_timeout(28800)。

The "image" column is a LONGBLOB

“image”列是一个LONGBLOB。

2 个解决方案

#1


0  

Try changing the column to a LONGBLOB

尝试将列更改为LONGBLOB。

#2


0  

I had a similar issue once and increasing log file helped. See "innodb_log_file_size" variable in my.ini - it usually needs to be twice as big as your blob. Although still at some point (like 200MB+) it may still not help...

我曾经遇到过类似的问题,并且增加了日志文件的帮助。请参阅我的“innodb_log_file_size”变量。它通常需要比你的blob大两倍。虽然仍然在某个点(比如200MB+),但它可能仍然没有帮助……

#1


0  

Try changing the column to a LONGBLOB

尝试将列更改为LONGBLOB。

#2


0  

I had a similar issue once and increasing log file helped. See "innodb_log_file_size" variable in my.ini - it usually needs to be twice as big as your blob. Although still at some point (like 200MB+) it may still not help...

我曾经遇到过类似的问题,并且增加了日志文件的帮助。请参阅我的“innodb_log_file_size”变量。它通常需要比你的blob大两倍。虽然仍然在某个点(比如200MB+),但它可能仍然没有帮助……