dbcli / mycli

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

status command is broken #1056

Open schmeic opened 2 years ago

schmeic commented 2 years ago

When I type status at the mycli prompt, it returns the string 'Flush commands', not the normal mysql status output that I was expecting. This is causing tests that rely on the output to break.

amjith commented 2 years ago

@schmeic What are you expecting to see when you run status?

I get the following output locally:

MySQL root@(none):(none)> status
--------------
mycli 1.25.0, running on CPython 3.9.9

+----------------------+------------------------------+
| Connection id:       | 12                           |
| Current database:    |                              |
| Current user:        | root@localhost               |
| Current pager:       | System default               |
| Server version:      | 8.0.29 Homebrew              |
| Protocol version:    | 10                           |
| Connection:          | Localhost via UNIX socket    |
| Server characterset: | utf8mb4                      |
| Db characterset:     | utf8mb4                      |
| Client characterset: | utf8mb3                      |
| Conn. characterset:  | utf8mb3                      |
| UNIX socket:         | /tmp/mysql.sock              |
| Uptime:              | 1 day 16 hours 49 min 33 sec |
+----------------------+------------------------------+

Connections: 1  Queries: 28  Slow queries: 0  Opens: 640  Flush tables: 4  Open tables: 92  Queries per second avg: 0.000
--------------
Time: 0.023s
schmeic commented 2 years ago

I was expecting to see something like that. However, all I see is the string 'Flush commands'. This is using both the version of mycli from pip and the version using the source code from github. Any idea why I would see this string instead of the normal output?

(none)> status
'Flush_commands'
(none)>
amjith commented 2 years ago

Are you using MySQL or a different flavor of mysql (maridb, percona, memsql etc)?

My setup is 8.0.29 of MySQL. I wonder if that makes a difference.

amjith commented 2 years ago

This is the python function that handles the status keyword.

https://github.com/dbcli/mycli/blob/main/mycli/packages/special/dbcommands.py#L50

schmeic commented 2 years ago

I am using MariaDB 10.5.16, but when I use the normal client with that, here's what I see:

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.5.16-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Connection id:      38
Current database:   
Current user:       schmeic@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server:         MariaDB
Server version:     10.5.16-MariaDB-1:10.5.16+maria~focal mariadb.org binary distribution
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:        /run/mysqld/mysqld.sock
Uptime:         2 hours 10 min 12 sec

Threads: 2  Questions: 93  Slow queries: 0  Opens: 34  Open tables: 27  Queries per second avg: 0.011
--------------

MariaDB [(none)]> 
schmeic commented 2 years ago

Ok, thanks for the link to the status function, I'll see if I can figure it out. Can you tell me where the output of the log.debug() goes?

amjith commented 2 years ago

You have to enable debug logging in the config file which is usually located in ~/.myclirc.

Then the debug log info goes to the regular log file which is located at ~/.mycli.log.

amjith commented 2 years ago

You'll have to change this setting: https://github.com/dbcli/mycli/blob/main/mycli/myclirc#L24

schmeic commented 2 years ago

Ok, thanks. I do see this in the log right now:

2022-06-03 08:57:10,522 (12747/MainThread) mycli.main ERROR - sql: 'status', error: KeyError('Flush_commands')

amjith commented 2 years ago

It's probably coming from this line: https://github.com/dbcli/mycli/blob/main/mycli/packages/special/dbcommands.py#L149

Try changing that to status.get('Flush_commands') and see if that gets past the issue.

schmeic commented 2 years ago

That fixed it, thanks!

schmeic commented 2 years ago

I have another test that's failing because of differences between mysql and mariadb: When we run mycli without arguments "port"

MariaDB connects using the socket, not TCP/IP. What should be done about this?

schmeic commented 2 years ago

One more failed test: When we create my.cnf file When we run mycli without arguments "host port user pass defaults_file"

Results in: 'Timeout exceeded.'

For some reason, I get a password prompt even though the password is in ~/.my.cnf. However, if I pass the user on the command line, like: mycli -u mycli it works fine. Using the mysql client with no args works, and logs in in without the password prompt.