Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Mycli – A CLI for MySQL with auto-completion and syntax highlighting (mycli.net)
106 points by amjith on July 30, 2015 | hide | past | favorite | 29 comments


I'm the author of this project. I'll be happy to answer any questions.

Brief Intro: This is a command line tool that is intended as a replacement for MySQL client.

It works with MySQL, MariaDB and Percona.

It is written in Python and it works in Python 2.6 to Python 3.4.

This is a counter part to http://pgcli.com.

MyCli was funded through Kickstarter (https://www.kickstarter.com/projects/1839007321/mysql-cli)


I tried installing it via pip on CentOS 6.6, and I get:

Traceback (most recent call last): File "/usr/bin/mycli", line 5, in <module> from pkg_resources import load_entry_point File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module> working_set.require(__requires__) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 648, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: six>=1.8

Am I missing something obvious?


I've heard it from someone else as well. I couldn't reproduce it myself.

The suggested solution was to uninstall mycli and reinstall directly from github.

pip uninstall mycli six; pip install https://github.com/dbcli/mycli/archive/master.zip


Yep, getting the same issue:

[foo@chef-solo ~]$ mycli Traceback (most recent call last): File "/usr/bin/mycli", line 5, in <module> from pkg_resources import load_entry_point File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module> working_set.require(__requires__) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 648, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: six>=1.8

Running sudo python install did the trick. I'm not sure I can really recommending anyone check this out without a working install from a package manager though.


Is there a way to have it bundled into a single file which I can scp to remote systems and need not worry about dependencies?


You could use pex which bundles up python requirements into an executable zip. I ran

    $ virtualenv PEX
    (PEX) $ pip install pex
    (PEX) $ pex mycli -e mycli.main:cli -o mycli.pex
    (PEX) $ deactivate
    $ chmod +x mycli.pex    
    $ ./mycli.pex
    Version: 1.0.1
    Chat: https://gitter.im/dbcli/mycli
    Mail: https://groups.google.com/forum/#!forum/mycli-users
    Home: http://mycli.net
    Thanks to the contributor - jweiland.net
    mysql user@localhost:(none)> 
You could scp the .pex to another host that also has python installed and it should run. You can also unzip it to inspect its contents...


Very cool! Thanks!


Did you try it with memsql? Just curious... I don't see any reason why it shouldn't work.


I don't fully understand your question. If you're asking whether this client will work with memsql, then the answer is No. Unless, memsql uses mysql protocol to talk to clients.

Mycli uses MySQL adapter called PyMySQL to connect to MySQL instances. I don't think it'll work with memsql.

If you're talking about writing a similar client for memsql, then yes it is possible to do that as long as there is a Python adapter for it.


MemSQL does use MySQL protocol to talk to clients.


You're right. I didn't know that.

http://docs.memsql.com/latest/faq/#is-memsql-a-storage-engin...

I haven't personally tried it with memsql.


This is really cool. I wanted to write an interactive input module for sqlite and I really struggled with GNU readline. It looks like I should try it again using python-prompt-toolkit. My use case would be something different than writing SQL statements, my module would let you create interactive, autocompleting input forms. I usually struggle inputting student exam scores into large spreadsheets and I want to replace that with sqlite.

And thanks for this one: https://github.com/jonathanslenders/python-prompt-toolkit/tr...


Yes! Python-prompt-toolkit has made it tremendously easy to write programs like mycli and pgcli.

The author has done an excellent job of keeping the APIs simple and intuitive.

It also helps that he's a good OSS maintainer (responsive and courteous). :)


humble and modest too ;)


I think they were talking about the author of Python-prompt-toolkit, though I read it that way too at first.


I gave it a spin. Seems pretty useful. Is there a way to view the last result again without re-running the query?

Also the keybindings are missing from the docs. For example on http://mycli.net/multi-line it says "You can enable multi-line mode by pressing key" but doesn't say which key to press. And on http://mycli.net/history it says "So press and then start typing your search term to see the queries", again doesn't say what to press.


Thank you for reporting the missing keys. I had them as <C-r> and <F3> but it was misinterpreted as html tags.

It is fixed now.

I'm not sure what you mean by view the results without re-running the query. Does scrolling not work? or do you mean if you launch a new session and want to see the results?

If you want to keep the results you can use audit logging feature (http://mycli.net/logging) which records every query and it's output into a file.


If the resulting table is large and opens up a less-like mode where I can scroll and pan around, but if I quit this mode, the terminal is cleared and there seems to be no way to take a second look at the data.


Can you tell me which OS you're using?

In Linux and OS X the less command should keep the output in the screen after you press 'q'.


I am on Linux too and it doesn't. Not just this tool: in general.


If you have 'less' on your system then it should work because I'm manipulating the options that are passed into less. I'm setting the less options here: https://github.com/dbcli/mycli/blob/master/mycli/main.py#L42...

You can try that from the command line yourself. Try:

less -SRXF <filename.txt>

That should print the file and not clear the screen when you press 'q'.

You can also override the pager to change from less to something else right from inside mycli. For example:

amjith@localhost:(none)> pager cat

That will use cat instead of less for paging the output and that should keep the output in the screen but it won't page them like less.


Looks really great! I think you should highlight better that it support fuzzy search, as I had to dig deep into Docs->Auto completion to find it (was about to suggest it to you).

Good luck with it!


Looks nice. Will give it a proper test drive soon.

Am currently using: http://ewaters.github.io/altsql-shell/

Software that few people know about.Worth others trying out too.

The data world really does need these more sane solutions.


Does is protect against auto-completing dangerous commands like 'DROP TABLE;'?


It still does auto-complete the DROP TABLE and DROP DATABASE, but it will ask for confirmation before running it.


Works perfect on Windows 10. Great tool!


Can I use this for mysql over ssh?


Any update on this?


Looks great, thank you!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: