dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.45k stars 662 forks source link

Make reconnect command create a new connection to the database #746

Open godhelpjun opened 5 years ago

godhelpjun commented 5 years ago

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 "

tsroten commented 5 years ago

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 commented 5 years ago

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

hyzgh commented 7 months ago

I also meet this problem.

hyzgh commented 7 months ago

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