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://my_user@my_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 \u@\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:

Comments
  • 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
  • Query results using tui interface

    Query results using tui interface

    The terminal show query results is awful when the table have so many fields. Can you do something like textual scrolling up and down and left and right to view data?

    https://github.com/Textualize/textual Textual is a Python framework for creating interactive applications that run in your terminal. image

    opened by brucmao 0
  • Add CodeQL workflow for GitHub code scanning

    Add CodeQL workflow for GitHub code scanning

    Hi dbcli/mycli!

    This is a one-off automatically generated pull request from LGTM.com :robot:. You might have heard that we’ve integrated LGTM’s underlying CodeQL analysis engine natively into GitHub. The result is GitHub code scanning!

    With LGTM fully integrated into code scanning, we are focused on improving CodeQL within the native GitHub code scanning experience. In order to take advantage of current and future improvements to our analysis capabilities, we suggest you enable code scanning on your repository. Please take a look at our blog post for more information.

    This pull request enables code scanning by adding an auto-generated codeql.yml workflow file for GitHub Actions to your repository — take a look! We tested it before opening this pull request, so all should be working :heavy_check_mark:. In fact, you might already have seen some alerts appear on this pull request!

    Where needed and if possible, we’ve adjusted the configuration to the needs of your particular repository. But of course, you should feel free to tweak it further! Check this page for detailed documentation.

    Questions? Check out the FAQ below!

    FAQ

    Click here to expand the FAQ section

    How often will the code scanning analysis run?

    By default, code scanning will trigger a scan with the CodeQL engine on the following events:

    • On every pull request — to flag up potential security problems for you to investigate before merging a PR.
    • On every push to your default branch and other protected branches — this keeps the analysis results on your repository’s Security tab up to date.
    • Once a week at a fixed time — to make sure you benefit from the latest updated security analysis even when no code was committed or PRs were opened.

    What will this cost?

    Nothing! The CodeQL engine will run inside GitHub Actions, making use of your unlimited free compute minutes for public repositories.

    What types of problems does CodeQL find?

    The CodeQL engine that powers GitHub code scanning is the exact same engine that powers LGTM.com. The exact set of rules has been tweaked slightly, but you should see almost exactly the same types of alerts as you were used to on LGTM.com: we’ve enabled the security-and-quality query suite for you.

    How do I upgrade my CodeQL engine?

    No need! New versions of the CodeQL analysis are constantly deployed on GitHub.com; your repository will automatically benefit from the most recently released version.

    The analysis doesn’t seem to be working

    If you get an error in GitHub Actions that indicates that CodeQL wasn’t able to analyze your code, please follow the instructions here to debug the analysis.

    How do I disable LGTM.com?

    If you have LGTM’s automatic pull request analysis enabled, then you can follow these steps to disable the LGTM pull request analysis. You don’t actually need to remove your repository from LGTM.com; it will automatically be removed in the next few months as part of the deprecation of LGTM.com (more info here).

    Which source code hosting platforms does code scanning support?

    GitHub code scanning is deeply integrated within GitHub itself. If you’d like to scan source code that is hosted elsewhere, we suggest that you create a mirror of that code on GitHub.

    How do I know this PR is legitimate?

    This PR is filed by the official LGTM.com GitHub App, in line with the deprecation timeline that was announced on the official GitHub Blog. The proposed GitHub Action workflow uses the official open source GitHub CodeQL Action. If you have any other questions or concerns, please join the discussion here in the official GitHub community!

    I have another question / how do I get in touch?

    Please join the discussion here to ask further questions and send us suggestions!

    opened by lgtm-com[bot] 0
  • odd login problem with ssl

    odd login problem with ssl

    I started seeing this error a month or two ago, when running mycli on the server:

    % mycli -u myuser
    Connecting to socket /var/run/mysqld/mysqld.sock, owned by user mysql
    [Errno 13] Permission denied
    

    Similar response with mycli -u root (as user root).

    The .mycli.log showed:

    2022-10-23 12:32:15,299 (279176/MainThread) mycli.config WARNING - Unable to parse line None of config file '/etc/mysql/my.cnf'.
    2022-10-23 12:32:15,299 (279176/MainThread) mycli.config WARNING - Using successfully parsed config values.
    2022-10-23 12:32:15,300 (279176/MainThread) mycli.config WARNING - Unable to parse line None of config file '/etc/mysql/conf.d/mysqldump.cnf'.
    2022-10-23 12:32:15,300 (279176/MainThread) mycli.config WARNING - Using successfully parsed config values.
    2022-10-23 12:32:15,302 (279176/MainThread) mycli.config WARNING - Unable to parse line None of config file '/etc/mysql/my.cnf'.
    2022-10-23 12:32:15,302 (279176/MainThread) mycli.config WARNING - Using successfully parsed config values.
    2022-10-23 12:32:15,303 (279176/MainThread) mycli.config WARNING - Unable to parse line None of config file '/etc/mysql/conf.d/mysqldump.cnf'.
    2022-10-23 12:32:15,303 (279176/MainThread) mycli.config WARNING - Using successfully parsed config values.
    2022-10-23 12:32:15,309 (279176/MainThread) mycli.main
    ERROR - traceback: 'Traceback (most recent call last):\n  File
      "/usr/lib/python3/dist-packages/mycli/main.py", line 482, in connect\n
      _connect()\n  File "/usr/lib/python3/dist-packages/mycli/main.py",
      line 456, in _connect\n    self.sqlexecute = SQLExecute(\n
      File "/usr/lib/python3/dist-packages/mycli/sqlexecute.py",
      line 119, in __init__\n    self.connect()\n  File
      "/usr/lib/python3/dist-packages/mycli/sqlexecute.py",
      line 179, in connect\n    conn = pymysql.connect(\n  File
      "/usr/lib/python3/dist-packages/pymysql/connections.py", line 285,
      in __init__\n    self.ctx = self._create_ssl_ctx(ssl)\n  File
      "/usr/lib/python3/dist-packages/pymysql/connections.py", line
      387, in _create_ssl_ctx\n    ctx.load_cert_chain(sslp["cert"],
      keyfile=sslp.get("key"))\nPermissionError: [Errno 13] Permission denied\n'
    
    

    indicating some SSL cert problem. Since I didn't care about SSL in this case and just wanted to connect via mysqld.sock, I opened sqlexecute.py in /usr/lib/python3/dist-packages/mycli and edited this line

    conn = pymysql.connect(
                database=db, user=user, password=password, host=host, port=port,
                unix_socket=socket, use_unicode=True, charset=charset,
                autocommit=True, client_flag=client_flag,
                local_infile=local_infile, conv=conv, ssl=ssl, program_name="mycli",
                defer_connect=defer_connect, init_command=init_command
            )
    
    

    changing ssl=ssl to ssl=''. This fixed the problem, but obviously not a permanent fix.

    Is this a bug, or is my system misconfigured? No trouble with anything else on the system, including SSL.

    Server: Ubuntu 22.04, mysqld Ver 8.0.30-0ubuntu0.22.04.1 for Linux

    opened by dougmccasland 0
  • Remove vi-mode bindings for prettify/unprettify functionality

    Remove vi-mode bindings for prettify/unprettify functionality

    Description

    Fixes #1087 .

    I thought this implementation was correct, but I don't use vi-mode, and we have an issue from a user who does. Best to remove the vi bindings. Perhaps someone who uses vi-mode can PR better bindings.

    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 rolandwalker 2
  • 'less' is not recognized as an internal or external command,

    'less' is not recognized as an internal or external command,

    Hello I've installed this program using pip install mycli. All the commands are working fine, but none of the data (tables, databases, are being displayed on the screen).

    Rather I keep getting the error: 'less' is not recognized as an internal or external command, operable program or batch file.

    image

    opened by kishorekumarxyz 4
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.8k Jan 2, 2023
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.8k Dec 31, 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 192 Jan 7, 2023
🦎 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 222 Jan 3, 2023
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 18.6k Jan 3, 2023
A terminal client for connecting to hack.chat servers

A terminal client for connecting to hack.chat servers.

V9 2 Sep 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 8 Dec 15, 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 270 Dec 29, 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 41.4k Jan 3, 2023
Lets you view, edit and execute Jupyter Notebooks in the terminal.

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

David Brochart 684 Dec 28, 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 40 Jan 3, 2023
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 150 Dec 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 29 Aug 9, 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 6.2k Jan 4, 2023
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 5 Dec 22, 2022
A Tempmail Tool for Terminal and Termux.

A Tempmail Tool for Terminal and Termux.

MAO-COMMUNITY 8 Oct 19, 2022