A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.

Overview

mycli

Build Status PyPI Join the chat at https://gitter.im/dbcli/mycli

A command line client for MySQL that can do auto-completion and syntax highlighting.

HomePage: http://mycli.net Documentation: http://mycli.net/docs

Completion CompletionGif

Postgres Equivalent: http://pgcli.com

Quick Start

If you already know how to install python packages, then you can install it via pip:

You might need sudo on linux.

$ pip install -U mycli

or

$ brew update && brew install mycli  # Only on macOS

or

$ sudo apt-get install mycli # Only on debian or ubuntu

Usage

$ mycli --help
Usage: mycli [OPTIONS] [DATABASE]

  A MySQL terminal client with auto-completion and syntax highlighting.

  Examples:
    - mycli my_database
    - mycli -u my_user -h my_host.com my_database
    - mycli mysql://[email protected]_host.com:3306/my_database

Options:
  -h, --host TEXT               Host address of the database.
  -P, --port INTEGER            Port number to use for connection. Honors
                                $MYSQL_TCP_PORT.
  -u, --user TEXT               User name to connect to the database.
  -S, --socket TEXT             The socket file to use for connection.
  -p, --password TEXT           Password to connect to the database.
  --pass TEXT                   Password to connect to the database.
  --ssh-user TEXT               User name to connect to ssh server.
  --ssh-host TEXT               Host name to connect to ssh server.
  --ssh-port INTEGER            Port to connect to ssh server.
  --ssh-password TEXT           Password to connect to ssh server.
  --ssh-key-filename TEXT       Private key filename (identify file) for the
                                ssh connection.
  --ssh-config-path TEXT        Path to ssh configuration.
  --ssh-config-host TEXT        Host for ssh server in ssh configurations (requires paramiko).
  --ssl-ca PATH                 CA file in PEM format.
  --ssl-capath TEXT             CA directory.
  --ssl-cert PATH               X509 cert in PEM format.
  --ssl-key PATH                X509 key in PEM format.
  --ssl-cipher TEXT             SSL cipher to use.
  --ssl-verify-server-cert      Verify server's "Common Name" in its cert
                                against hostname used when connecting. This
                                option is disabled by default.
  -V, --version                 Output mycli's version.
  -v, --verbose                 Verbose output.
  -D, --database TEXT           Database to use.
  -d, --dsn TEXT                Use DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-dsn                    list of DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-ssh-config             list ssh configurations in the ssh config (requires paramiko).
  -R, --prompt TEXT             Prompt format (Default: "\t \[email protected]\h:\d> ").
  -l, --logfile FILENAME        Log every query and its results to a file.
  --defaults-group-suffix TEXT  Read MySQL config groups with the specified
                                suffix.
  --defaults-file PATH          Only read MySQL options from the given file.
  --myclirc PATH                Location of myclirc file.
  --auto-vertical-output        Automatically switch to vertical output mode
                                if the result is wider than the terminal
                                width.
  -t, --table                   Display batch output in table format.
  --csv                         Display batch output in CSV format.
  --warn / --no-warn            Warn before running a destructive query.
  --local-infile BOOLEAN        Enable/disable LOAD DATA LOCAL INFILE.
  --login-path TEXT             Read this path from the login file.
  -e, --execute TEXT            Execute command and quit.
  --init-command TEXT           SQL statement to execute after connecting.
  --charset TEXT                Character set for MySQL session.
  --help                        Show this message and exit.

Features

mycli is written using prompt_toolkit.

  • Auto-completion as you type for SQL keywords as well as tables, views and columns in the database.
  • Syntax highlighting using Pygments.
  • Smart-completion (enabled by default) will suggest context-sensitive completion.
    • SELECT * FROM <tab> will only show table names.
    • SELECT * FROM users WHERE <tab> will only show column names.
  • Support for multiline queries.
  • Favorite queries with optional positional parameters. Save a query using \fs alias query and execute it with \f alias whenever you need.
  • Timing of sql statements and table rendering.
  • Config file is automatically created at ~/.myclirc at first launch.
  • Log every query and its results to a file (disabled by default).
  • Pretty prints tabular data (with colors!)
  • Support for SSL connections

Contributions:

If you're interested in contributing to this project, first of all I would like to extend my heartfelt gratitude. I've written a small doc to describe how to get this running in a development setup.

https://github.com/dbcli/mycli/blob/master/CONTRIBUTING.md

Please feel free to reach out to me if you need help.

My email: [email protected]

Twitter: @amjithr

Detailed Install Instructions:

Fedora

Fedora has a package available for mycli, install it using dnf:

$ sudo dnf install mycli

RHEL, Centos

I haven't built an RPM package for mycli for RHEL or Centos yet. So please use pip to install mycli. You can install pip on your system using:

$ sudo yum install python-pip

Once that is installed, you can install mycli as follows:

$ sudo pip install mycli

Windows

Follow the instructions on this blogpost: https://www.codewall.co.uk/installing-using-mycli-on-windows/

Cygwin

  1. Make sure the following Cygwin packages are installed: python3, python3-pip.
  2. Install mycli: pip3 install mycli

Thanks:

This project was funded through kickstarter. My thanks to the backers who supported the project.

A special thanks to Jonathan Slenders for creating Python Prompt Toolkit, which is quite literally the backbone library, that made this app possible. Jonathan has also provided valuable feedback and support during the development of this app.

Click is used for command line option parsing and printing error messages.

Thanks to PyMysql for a pure python adapter to MySQL database.

Compatibility

Mycli is tested on macOS and Linux.

Mycli is not tested on Windows, but the libraries used in this app are Windows-compatible. This means it should work without any modifications. If you're unable to run it on Windows, please file a bug.

Configuration and Usage

For more information on using and configuring mycli, check out our documentation.

Common topics include:

Issues
  • test mycli using pexpect

    test mycli using pexpect

    Description

    test mycli using pexpect (this way the tty code path can be tested)

    Checklist

    • [x] I've added this contribution to the changelog.md.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    opened by meeuw 67
  • Add generic output formatter interface.

    Add generic output formatter interface.

    Description

    • Adds a generic OutputFormatter class with all of tabulate's output formats.
    • Moves expanded output to the output formatter.
    • Adds terminaltables formats.

    Checklist

    • [x] I've added this contribution to the changelog.md.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    opened by tsroten 37
  • pip install mycli on linux error

    pip install mycli on linux error

    This error:

    SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/mycli/main.py', 174, 29, ' return {x: get(x) for x in keys}\n'))

    opened by polaris1119 30
  • Add stdin batch mode.

    Add stdin batch mode.

    This pull request adds support for reading commands from stdin. It works similar to the mysql client. If you pipe commands to mycli like this:

    cat test.sql | mycli
    

    or this

    mycli < test.sql
    

    Then, mycli will output the results in a plain, tab-separated format (no padding or status messages). If you use the -t/--table argument, then mycli will output the results in your configured table format.

    After processing stdin, mycli will quit.

    I can also see use for a yet-to-be-added (different PR) verbose mode that will add support for displaying the commands that are running as well as possibly status messages.

    This addresses #179.

    opened by tsroten 26
  • Replace tabulate with terminaltables.

    Replace tabulate with terminaltables.

    @meeuw @tsroten @j-bennet

    This is my first attempt at replacing the tabulate library with an alternative. It is in no way near shippable quality. I'm just putting it out there as a prototype. I'll keep polishing it and you're all welcome to take a stab at it as well. Let's collaborate on this branch.

    Checklist

    • [ ] I've added this contribution to the changelog.md.
    • [ ] I've added my name to the AUTHORS file (or it's already there).
    opened by amjith 25
  • Read more options from my.cnf

    Read more options from my.cnf

    Just a list of options I'm currently using and that would be nice to have automatcially in mycli

    [mysql]
    pager = mypager  # https://github.com/romuald/mypager
    safe-updates
    max-join-size=1000000000
    

    They all seem to work nicely within the CLI, but aren't loaded automatically

    enhancement 
    opened by romuald 25
  • Add styled/colored output.

    Add styled/colored output.

    Description

    This adds styled output (headers, odd row, even rows). Configuring it is the same as the current styles (i.e. Pygments token-type strings). It defaults the config file to do bold headers.

    This addresses #364.

    ~~The tests will fail until CLI Helpers is released with https://github.com/dbcli/cli_helpers/pull/10.~~

    Checklist

    • [x] I've added this contribution to the changelog.md.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    opened by tsroten 23
  • Last command in multi-command query not executed

    Last command in multi-command query not executed

    When multi_line is set to true and pasting, e.g.:

    use mysql;
    select User from user;
    

    The last command is not executed.

    The command pastes on a single line with the semi colon delimiter but the last command is not executed, pasting:

    use mysql;
    select User from user;
    select User from user;
    

    only returns one resultset from the user query.

    EDIT: This is on version 1.4.0 on Debian Jessie.

    bug 
    opened by alasdairdc 23
  • Ctrl+C on destructive action prompt should not abort the CLI

    Ctrl+C on destructive action prompt should not abort the CLI

    I occasionally pressed arrow keys on the prompt, then Ctrl+C and got the CLI aborted. I think it would be more convenient to accept the combination as 'No' answer.

    image

    enhancement 
    opened by atapin 22
  • output via generator

    output via generator

    Description

    output via generator to prevent:

    • buffering of the complete output
    • joining and splitting the output

    Checklist

    • [x] I've added this contribution to the changelog.md.
    in progress 
    opened by meeuw 20
  • Fix requirements

    Fix requirements

    Description

    I've did some quite naïve tests (only run pytest & start mycli) and changed the following minimum requirements for mycli.

    Pygments lowered to >= 1.6 PyMySQL raised to >= 0.6.7 configobj lowered to 5.0.5 pycryptodome set minimum to 3

    Checklist

    • [x] I've added this contribution to the changelog.md.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    opened by meeuw 20
  • status command is broken

    status command is broken

    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.

    opened by schmeic 13
  • Adding a new

    Adding a new "TLS version" argument to mycli command line options ?

    Hello,

    Is it possible to add a new argument to provide a specific version of TLS while connecting to database via mycli command line options ?

    Thanks in advance!

    Regards, Pavan.

    opened by PavanTatikonda 1
  • Prompt for password if lc-messages are not set to en_US

    Prompt for password if lc-messages are not set to en_US

    mycli don't promt for needed password, if lc-messages are set to other language than english. In #7 issue (https://github.com/dbcli/mycli/issues/7), is patch, that solve this only for english language (https://github.com/dbcli/mycli/commit/0ec133cbc03264fc92e06c7f5baaf4a415cd7eee#diff-8e9c55cacc296c33014d775f5deffcb0aafeac0e0026ffebb9acb60911becc25R129). If I set lc-messages to i.e. cs_CZ on server, then isn't any way to force mycli to prompt for password. Original mysql client work well, because I can force prompting it for password by -p switch. May mycli can copy this behavior or can add other switch, for force show password prompt?

    opened by ByCzech 0
  • Fix dbcliorg/mycli:latest on docker hub

    Fix dbcliorg/mycli:latest on docker hub

    dbcliorg/mycli:latest disappeared from docker hub and has been replaced by the wrongly spelled dbcliorg/mycli:lastest. Please note the extra s in lastest.

    Please reupload a properly named image to docker hub :) Thanks!

    opened by ChristianCiach 2
  • Missing importlib-resources dependency for Python 3.6

    Missing importlib-resources dependency for Python 3.6

    pip installing this under Python 3.6 and running mycli will lead to the following error,

    Traceback (most recent call last):
      File "...../lib64/python3.6/site-packages/mycli/config.py", line 14, in <module>
        import importlib.resources as resources
    ModuleNotFoundError: No module named 'importlib.resources'
    

    Installing the importlib-resources library separately fixes the issue. We need to list this as a dependency for Python 3.6

    opened by koallen 3
  • Slow query - not due to pager.

    Slow query - not due to pager.

    Hey, there seems to be a problem of slow queries not related to pager. I also tested with mariadb 10.4.xx with the same results.

    Here are some details : With mycli:

    MariaDB 10.3.34
    mycli 1.24.1
    Home: http://mycli.net
    Bug tracker: https://github.com/dbcli/mycli/issues
    Thanks to the contributor - Heath Naylor
    MariaDB [email protected]:(none)> use mydb;
    You are now connected to database "mydb" as user "groot"
    Time: 0.001s
    MariaDB [email protected]:mydb> select * from customer
    110016 rows in set
    Time: 119.905s
    MariaDB [email protected]:mydb> pager pspg -s 5
    PAGER set to pspg -s 5.
    Time: 0.001s
    MariaDB [email protected]:mydb> select * from customer
    110016 rows in set
    Time: 121.547s
    

    With mysql:

    MariaDB [mydb]> select * from customer;
    110016 rows in set (0.224 sec)
    MariaDB [mydb]> desc customer;
    15 rows in set (0.001 sec)
    
    | Field           |      Type        | Null | Key | Default |     Extra      |
    +-----------------+------------------+------+-----+---------+----------------+
    | id              | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | username        | varchar(60)      | YES  | UNI | NULL    |                |
    | password        | varchar(64)      | YES  |     | NULL    |                |
    | civility        | smallint(6)      | NO   |     | 0       |                |
    | lastname        | varchar(100)     | NO   |     | NULL    |                |
    | firstname       | varchar(100)     | NO   |     | NULL    |                |
    | homephone       | varchar(16)      | YES  |     | NULL    |                |
    | cellphone       | varchar(16)      | YES  |     | NULL    |                |
    | alert_comment   | varchar(255)     | YES  |     | NULL    |                |
    | visible_comment | varchar(255)     | YES  |     | NULL    |                |
    | cuac_id         | int(11)          | YES  |     | NULL    |                |
    | token           | varchar(32)      | YES  |     | NULL    |                |
    | active          | tinyint(1)       | NO   |     | 1       |                |
    | is_key_account  | tinyint(1)       | NO   |     | NULL    |                |
    | outstanding_max | decimal(20,3)    | YES  |     | NULL    |                |
    +-----------------+------------------+------+-----+---------+----------------+
    
    
    opened by sgorange 0
Owner
dbcli
Better CLIs for Databases
dbcli
Postgres CLI with autocompletion and syntax highlighting

A REPL for Postgres This is a postgres client that does auto-completion and syntax highlighting. Home Page: http://pgcli.com MySQL Equivalent: http://

dbcli 10.5k Jun 29, 2022
CLI for SQLite Databases with auto-completion and syntax highlighting

litecli Docs A command-line client for SQLite databases that has auto-completion and syntax highlighting. Installation If you already know how to inst

dbcli 1.6k Jul 4, 2022
AthenaCLI is a CLI tool for AWS Athena service that can do auto-completion and syntax highlighting.

Introduction AthenaCLI is a command line interface (CLI) for the Athena service that can do auto-completion and syntax highlighting, and is a proud me

dbcli 188 Jun 21, 2022
🦎 A NeoVim plugin for highlighting visual selections like in a normal document editor!

?? HighStr.nvim A NeoVim plugin for highlighting visual selections like in a normal document editor! Demo TL;DR HighStr.nvim is a NeoVim plugin writte

Pocco81 171 Jun 28, 2022
Gamestonk Terminal is an awesome stock and crypto market terminal

Gamestonk Terminal is an awesome stock and crypto market terminal. A FOSS alternative to Bloomberg Terminal.

Gamestonk Terminal 12.5k Jul 2, 2022
A terminal client for connecting to hack.chat servers

A terminal client for connecting to hack.chat servers.

V9 2 Jun 21, 2022
TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal.

TerminalGV So I got bored in the train, TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal. The "on-tr

Samuel 7 Mar 6, 2022
Python Library and CLI for exporting MySQL databases

expdb Python library and CLI for exporting MySQL databases Installation Pre-requisites MySQL server Python 3.9+ Using git Clone the repository to your

Devansh Singh 1 Nov 29, 2021
Random scripts and other bits for interacting with the SpaceX Starlink user terminal hardware

starlink-grpc-tools This repository has a handful of tools for interacting with the gRPC service implemented on the Starlink user terminal (AKA "the d

null 197 Jul 4, 2022
Rich is a Python library for rich text and beautiful formatting in the terminal.

The Rich API makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box.

Will McGugan 38.3k Jul 3, 2022
Lets you view, edit and execute Jupyter Notebooks in the terminal.

Lets you view, edit and execute Jupyter Notebooks in the terminal.

David Brochart 604 Jul 3, 2022
Module for converting 2D Python lists to fancy ASCII tables. Table2Ascii lets you display pretty tables in the terminal and on Discord.

table2ascii Module for converting 2D Python lists to a fancy ASCII/Unicode tables table2ascii ?? Installation ??‍?? Usage Convert lists to ASCII table

Jonah Lawrence 25 Jun 27, 2022
A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

Kyle Harrison 146 Jun 14, 2022
CLabel is a terminal-based cluster labeling tool that allows you to explore text data interactively and label clusters based on reviewing that data.

CLabel is a terminal-based cluster labeling tool that allows you to explore text data interactively and label clusters based on reviewing that

Peter Baumgartner 28 Jun 19, 2022
This CLI give the possibility to do a queries in Star Wars API and returns a JSON in a terminal.

Star Wars CLI (swcli) This CLI give the possibility to do a queries in Star Wars API and returns a JSON in a terminal. Install $ pip install swcli Qu

Pery Lemke 5 Nov 5, 2021
WA Terminal is a CLI application that allows us to login and send message with WhatsApp with a single command.

WA Terminal is a CLI application that allows us to login and send message with WhatsApp with a single command.

Aziz Fikri 15 Apr 15, 2022
A terminal spreadsheet multitool for discovering and arranging data

VisiData v2.6.1 A terminal interface for exploring and arranging tabular data. VisiData supports tsv, csv, sqlite, json, xlsx (Excel), hdf5, and many

Saul Pwanson 5.6k Jun 29, 2022
A useful and easy to use Terminal Timer made with Python.

Terminal SpeedCubeTimer Installation ¡No requirements! Just Download and play Usage Starts timer.py and you will see this. python timer.py Scramble

Achalogy 4 Jun 23, 2022
A Tempmail Tool for Terminal and Termux.

A Tempmail Tool for Terminal and Termux.

MAO-COMMUNITY 7 Jun 18, 2022