我得到了错误代码:2013。当我试图使用MySQL工作台向表添加索引时,在查询错误期间失去了与MySQL服务器的连接。 我还注意到,每当我运行长查询时,它就会出现。

是否有增加超时值的方法?


当前回答

如果您在恢复一个大转储文件期间遇到这个问题,并且可以排除与网络有关的问题(例如在本地主机上执行),那么我的解决方案可能会有帮助。

我的mysqldump至少有一个INSERT太大,mysql无法计算。你可以通过输入show变量"net_buffer_length";在你的mysql-cli中。 你有三种可能:

increase net_buffer_length inside mysql -> this would need a server restart create dump with --skip-extended-insert, per insert one line is used -> although these dumps are much nicer to read this is not suitable for big dumps > 1GB because it tends to be very slow create dump with extended inserts (which is the default) but limit the net-buffer_length e.g. with --net-buffer_length NR_OF_BYTES where NR_OF_BYTES is smaller than the server's net_buffer_length -> I think this is the best solution, although slower no server restart is needed.

我使用以下mysqldump命令: mysqldump——skip-comments——set-charset——default-character-set=utf8——single-transaction——net-buffer_length 4096 DBX >转储文件

其他回答

使用命令行选项net_read_timeout / wait_timeout和一个合适的值(以秒为单位)启动DB服务器,例如:——net_read_timeout=100。

参考资料见这里和这里。

在“编辑->首选项->SQL编辑器->MySQL会话”中修改“读取超时”时间

如果您正在使用SQL工作台,您可以尝试使用索引,通过添加索引到您的表,要添加索引,单击扳手(扳手)符号在表上,它应该打开表的设置,下面,单击索引视图,键入索引名称并设置类型为索引,在索引列中,选择表中的主列。

对其他表上的其他主键执行相同的步骤。

如果您在恢复一个大转储文件期间遇到这个问题,并且可以排除与网络有关的问题(例如在本地主机上执行),那么我的解决方案可能会有帮助。

我的mysqldump至少有一个INSERT太大,mysql无法计算。你可以通过输入show变量"net_buffer_length";在你的mysql-cli中。 你有三种可能:

increase net_buffer_length inside mysql -> this would need a server restart create dump with --skip-extended-insert, per insert one line is used -> although these dumps are much nicer to read this is not suitable for big dumps > 1GB because it tends to be very slow create dump with extended inserts (which is the default) but limit the net-buffer_length e.g. with --net-buffer_length NR_OF_BYTES where NR_OF_BYTES is smaller than the server's net_buffer_length -> I think this is the best solution, although slower no server restart is needed.

我使用以下mysqldump命令: mysqldump——skip-comments——set-charset——default-character-set=utf8——single-transaction——net-buffer_length 4096 DBX >转储文件

SET @@local.net_read_timeout=360;

警告:当您在远程连接中应用它时,以下将不起作用:

SET @@global.net_read_timeout=360;

编辑:360是秒数