客戶端如果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服務端如何配置才能解決此問題?
uj5u.com熱心網友回復:
這個一般跟服務器和資料庫的設定有關,監控到你段時間沒使用,就會主動把你踢出聯接。建議你用短連接,用完之后關掉MyConnection.Close,要的時候重新MyConnection.openuj5u.com熱心網友回復:
使用的時候判斷一次連接是否正常, 斷開則重連.轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/15948.html
標籤:數據庫相關
下一篇:Tails系統
