Home > Back-end >  Why the mysql associated active connections?
Why the mysql associated active connections?

Time:11-05

Client if 10 minutes without any query operations, the query again, will be submitted to the following error:
Lost connection to MySQL server during query
As shown in the figure below:


The server related configuration is as follows:
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 version 8.0.

Connect to the database using MyDAC associated control, connect to the database code is as follows:
The function CreateMysqlCon (const AsDbHost AsDbPort, AsDbUser, AsDbPassword, AsDbName: string; Var AMyConnection: TMyConnection; Var AsMsg: string) : Boolean;
The 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: the Exception do
The begin
AsMsg:='connection mysql database failed, the reason: "+ e.M essage.
Result:=False;
end;
end;
end;

Excuse me, is how MYSQL server configuration to solve this problem?

CodePudding user response:

This generally associated with server and database Settings, monitor to you don't use period of time, will take the initiative to kick you out, suggest you use short connection, use after turn off MyConnection. Close, want when to MyConnection. Open

CodePudding user response:

Judgment when you use a connection whether normal, disconnect the reconnection.
  • Related