mycli icon indicating copy to clipboard operation
mycli copied to clipboard

Make reconnect command create a new connection to the database

Open godhelpjun opened this issue 5 years ago • 4 comments

when mycli command line is idle for long time,then the connection is lost.When I try to reconnect using command \r mydb it takes time so long to wait for displaying reconnecting .... once I see the Reconnecting..... displayed It connect to server so fast. so,I wonder why it take me so long to wait,even slower a new command line " mycli -hhost -ppass -uroot "

godhelpjun avatar May 25 '19 13:05 godhelpjun

Hi @godhelpjun! Thanks for reporting this. It does appear that the reconnect command in mycli is reconnecting through kind of an indirect means. I think we can try to improve on that a little bit.

As a workaround, instead of trying to reconnect, if you simply try to execute a query, mycli should automatically try to reconnect. In my experience that tends to be faster. It looks like this:

mycli> select * from users limit 5;
Reconnecting...

After it reconnects, you will either get the output of the query, or a message letting you know that the reconnection attempt failed.

tsroten avatar May 26 '19 21:05 tsroten

A note for changing the reconnect command. In the MySQL client, running the reconnect command actually gets a new connection ID. In mycli, it is a synonym for the use command.

We should make the reconnect command actually try to connect to the database again. Here is the logic we use to automatically reconnect to the database: https://github.com/dbcli/mycli/blob/master/mycli/main.py#L662-L667

tsroten avatar May 26 '19 21:05 tsroten

I also meet this problem.

hyzgh avatar Mar 05 '24 07:03 hyzgh

@tsroten When I execute a query when mycli command line is idle for long time, reconnect is also slow,about 8 seconds even more.

hyzgh avatar Mar 05 '24 07:03 hyzgh