mysql为何会主动关联连接?

taste品味 2020-02-12 08:43:16
客户端如果10分钟左右没有任何查询操作,再次查询时,会报以下错误:
Lost connection to MySQL server during query
如下图所示:


服务器相关配置如下:
max_allowed_packet 524288000
mysqlx_max_allowed_packet 67108864
slave_max_allowed_packet 1073741824
connect_timeout 10
delayed_insert_timeout 300
have_statement_timeout YES
innodb_flush_log_at_timeout 1
innodb_lock_wait_timeout 50
innodb_rollback_on_timeout OFF
interactive_timeout 28800
lock_wait_timeout 31536000
mysqlx_connect_timeout 30
mysqlx_idle_worker_thread_timeout 60
mysqlx_interactive_timeout 28800
mysqlx_port_open_timeout 0
mysqlx_read_timeout 30
mysqlx_wait_timeout 28800
mysqlx_write_timeout 60
net_read_timeout 30
net_write_timeout 60
rpl_stop_slave_timeout 31536000
slave_net_timeout 60
wait_timeout 28800



MYSQL版本8.0.

连接数据库采用MyDAC相关控件,连接数据库的代码如下:
function CreateMysqlCon(const AsDbHost, AsDbPort, AsDbUser, AsDbPassword, AsDbName :string; var AMyConnection :TMyConnection; var AsMsg :string):Boolean;
begin

try
if not Assigned(AMyConnection) then
AMyConnection := TMyConnection.Create(nil);
AMyConnection.Close;
AMyConnection.LoginPrompt := False;
AMyConnection.Server := AsDbHost;
AMyConnection.Port := StrToInt(AsDbPort);
AMyConnection.Username := AsDbUser;
AMyConnection.Password := AsDbPassword;
AMyConnection.Database := AsDbName;
AMyConnection.Options.UseUnicode := True;
//g_MySqlCon.Options.KeepDesignConnected := False;
AMyConnection.Options.Charset := 'utf8';
AMyConnection.ConnectionTimeout := 15;
AMyConnection.Options.Interactive := True;
AMyConnection.Open;

Result := True;
except
on e:Exception do
begin
AsMsg := '连接mysql数据库失败,原因:' + e.Message;
Result := False;
end;
end;
end;

请问是MYSQL服务端如何配置才能解决此问题?
...全文
275 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
道玄希言 2020-02-19
  • 打赏
  • 举报
回复
使用的时候判断一次连接是否正常, 断开则重连.
ron_xin 2020-02-13
  • 打赏
  • 举报
回复
这个一般跟服务器和数据库的设置有关,监控到你段时间没使用,就会主动把你踢出联接。建议你用短连接,用完之后关掉MyConnection.Close,要的时候重新MyConnection.open

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧