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
  • 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
  • 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
  • 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
  • Feature request : Read the ~/.mylogin.cnf file at startup

    Feature request : Read the ~/.mylogin.cnf file at startup

    Hi, Would it be possible that mycli takes ~/.my.cnf ? Thanks

    opened by rapha8l 22
  • 'str' object has no attribute 'parent'

    'str' object has no attribute 'parent'

    I installed mycli from AUR. when i try to use show tables it gives error as shown in title

    sudo mycli -u root
    Connecting to socket /var/run/mysqld/mysqld.sock, owned by user mysql
    MariaDB 10.6.5
    mycli 1.24.1
    Home: http://mycli.net
    Bug tracker: https://github.com/dbcli/mycli/issues
    Thanks to the contributor - Zhidong
    MariaDB [email protected](none):(none)> use practice;
    You are now connected to database "practice" as user "root"
    Time: 0.001s
    MariaDB [email protected](none):practice> show tables;
    'str' object has no attribute 'parent'
    MariaDB [email protected](none):practice>
    
    opened by Atomnp 9
  • favorite_queries as a SOURCE command

    favorite_queries as a SOURCE command

    in ~/.myclirc file I have

    [favorite_queries]
    q1 = '''SOURCE /Users/eric/InWork/sql/q1.sql;'''
    

    Then attempting to list and run it, I get error 1064. Any ideas if the SOURCE command is allowed here? or do I have to include the SQL query code itself? Or do I have the above configuration wrong?

    MySQL [email protected]:(none)> \f
    +------+---------------------------------------------------+
    | Name | Query                                             |
    +------+---------------------------------------------------+
    | q1  | SOURCE /Users/eric/InWork/sql/q1.sql; |
    +------+---------------------------------------------------+
    
    MySQL [email protected]:(none)> \f q1
    (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE /Users/eric/InWork/sql/q1.sql' at line 1")
    
    opened by ericdp 0
  • Garbled when Excel open the output csv

    Garbled when Excel open the output csv

    I want to output my sql query results to a csv file,So I used this command: \T csv ; \o ./export.csv ; SELECT 1,2,3; Opening this file with a text editor like notepad++ is normal,but when you open it in excel, it messes up the code.I think it's because this csv doesn't have a bom,Is there a way to specify the output of a utf-8 csv with bom?

    opened by WainWong 0
  • default limit

    default limit

    how to set default limit ?

    other client will be set default limit ~ for example sequel pro "Preferences -> Tables -> Limit result to : 1000 rows " , navicat "Preferences -> Records -> Limit rcords 1000 records per page"

    opened by AKMCC-hub 0
  • encoding issue

    encoding issue

    When I use mycli -h host -u user for a remote access, it shows the error: unicodedecodeerror: 'utf-8' codec can't decode byte 0xa8 in position 52: invalid start byte

    For fix this issue, I must manually modify the .myclirc file

    # \R - The current time, in 24-hour military time (0-23) 
    # \r - The current time, standard 12-hour time (1-12)
    

    Change the "-" (it looks a bit longer than the correct one) at the end to the one that we can type from our keyboard

    opened by BlckKn1fe 0
  • [Feature Request] Code snippets

    [Feature Request] Code snippets

    Would it be possible to have code snippets, like common queries. I find myself typing this a lot over course of the day:

    SELECT X, Y FROM TABLE WHERE Z = ''

    or similar queries.

    It would be nice nice to be able to have snippets that you can expand. So for example, typing SELECT then pressing tab would result in:

    SELECT _ FROM _

    The cursor would be on the first underscore. This is obviously just an example, it could work for many type of queries.

    opened by Herz3h 2
  • Couldn't fine SQL state code in log.

    Couldn't fine SQL state code in log.

    When I did something wrong, I can only see MySQL server error without SQL state code. This may lead to hardship in debugging.

    opened by BNSWT 0
  • Is mycli must type return to execute command?

    Is mycli must type return to execute command?

    When i paste command to origin mysql console with return, it can execute immediately But i paste command to mycli console with return, i need type return to execute

    opened by liuende501 0
  • Suppress

    Suppress "Error: Unable to read login path file."

    Errors should indicate something that makes the program not run as expected; this error appears even when it has no effect on the program's functionality. This error message should be removed in cases where the login path file is not needed, or at least have an option to suppress it.

    opened by pixarbuff 0
  • contributing and running tests

    contributing and running tests

    I'd like to start contributing, and I followed the steps in CONTRIBUTING.md and then tried to run the version of mycli in my virtualenv bin dir. I got module not found errors and had to install the following extra modules: pyperclip, importlib_resources, pyaes

    Should these be added to requirements-dev.txt?

    Also, to run the tests you need to connect to mysql as a user that can create and drop tables, with the default user being root. This seems pretty dangerous. Why not use a database prefix, like mycli_, and then create a test user that only has access to tables starting with this prefix?

    opened by schmeic 2
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 10k Jan 15, 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.5k Jan 11, 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 174 Jan 11, 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 132 Jan 13, 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 8.9k Jan 17, 2022
A terminal client for connecting to hack.chat servers

A terminal client for connecting to hack.chat servers.

V9 1 Nov 13, 2021
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 3 Jan 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 135 Jan 2, 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 33.9k Jan 21, 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 542 Jan 19, 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 17 Jan 12, 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 135 Jan 12, 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 27 Oct 30, 2021
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 16 Oct 30, 2021
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 4.7k Jan 12, 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 3 Nov 19, 2021
A Tempmail Tool for Terminal and Termux.

A Tempmail Tool for Terminal and Termux.

MAO-COMMUNITY 3 Jan 8, 2022