In this guide, we will do the installation and usage of mycli on Ubuntu 18.04. Mycli is a MySQL terminal client written in Python and Python Prompt Toolkit library with AutoCompletion and Syntax Highlighting. It works with MySQL, MariaDB, and Percona database servers.
mycli exist to help you write complex queries easily and faster without the hassle of having to remember the whole query syntax. It uses REPL (Read, Eval, Print, Loop) which pop up suggestion menu as soon as you start typing.
Features of mycli
Here is the complete list of mycli features as listed in the official website.
- 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 queryand execute it with
\f aliaswhenever you need.
- The timing of sql statements and table rendering.
- Config file is automatically created at
~/.myclircon the first launch.
- Log every query and its results to a file (disabled by default).
- Pretty prints tabular data (with colors!)
- Support for SSL connections
How to install mycli on Ubuntu 18.04
mycli can be installed using
pip python package manager or from
Install mycli from apt repository
sudo apt update sudo apt install mycli
Install mycli using pip
sudo apt install python-pip sudo pip install mycli
sudo easy_install mycli
How to use mycli
Note that the suggestions are context sensitive based on the position of the cursor. eg: Only tables are suggested after the FROM keyword, only column names are suggested after the WHERE clause.
With Smart Completion ON, Only table names from the current database are suggested after the FROM keyword and Column names from the current table are suggested after the WHERE clause.
To view usage man page, use the command:
# mycli --help Usage: mycli [OPTIONS] [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 --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 Version of mycli. -D, --database TEXT Database to use. -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 config group with the specified suffix. --defaults-file PATH Only read default options from the given 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. --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 query to the database. --help Show this message and exit.
See below example which connect to the local MariaDB database server as a root user:
# mycli -h localhost -u root Password: Version: 1.8.1 Chat: https://gitter.im/dbcli/mycli Mail: https://groups.google.com/forum/#!forum/mycli-users Home: http://mycli.net Thanks to the contributor - Nathan Taggart mariadb [email protected]:(none)>
Typing SHOW and space shows valid options
If you switch to a database and type SELECT * FROM followed by <tab>, all options listed should be for the tables in the current database, and WHERE <tab> will only show column names.
For more information on using and configuring mycli, check the official documentation.