Managing relational databases from the command line is an essential task for system administrators, developers, and database engineers. While the standard mysql client has been a dependable default for decades, it lacks modern productivity features such as context-sensitive syntax highlighting, auto-completion of table and column names, and multi-line editing. mycli is an open-source, terminal-based front-end for MySQL and MariaDB that brings rich auto-completion, intelligent suggestions, and syntax styling directly into your shell environment.
Written in Python and built on top of the python-prompt-toolkit library, mycli suggests SQL keywords, table names, column definitions, and schema functions as you type. It also formats query output in clear ASCII tables, supports custom themes, and remembers your command history across database sessions. In this guide, you will learn how to install mycli across various Linux distributions, establish secure connections to local and remote databases, configure custom styling options, and use its productivity features.
Why Choose mycli Over the Default MySQL Client?
Working with complex database schemas often requires constantly running DESCRIBE table_name; or consulting external database diagrams to recall exact column names. The standard command line does not provide context-aware feedback, leading to frequent typos and invalid queries. mycli resolves these common workflow bottlenecks:
- Smart Auto-Completion: As you type SQL queries,
mycliinspects the connected database catalog and suggests matching table names, view names, column names, and SQL keywords based on the query context. - Syntax Highlighting: SQL commands, strings, numeric literals, and comments are colour-coded in real time, making syntax errors obvious before query execution.
- Rich Table Formatting: Tabular query results are rendered with clean borders and column alignments that scale neatly to terminal width.
- Multi-Line Query Support: Complex multi-line queries can be drafted, edited, and formatted without prematurely executing half-finished statements.
- Configuration Flexibility: Users can customise key bindings (including Vi and Emacs editing modes), colour palettes, and query logging behaviour via a simple configuration file.
Step 1: Install mycli on Linux
mycli is packaged in the official repositories of major Linux distributions and is also available through Python’s package manager, pipx or pip. Choose the installation method suitable for your distribution.
Installing on Debian, Ubuntu, and Linux Mint
On Debian-based systems, install mycli using apt:
sudo apt update
sudo apt install mycli -y
Installing on Fedora, RHEL, and AlmaLinux
On Fedora and modern Enterprise Linux distributions, install mycli using dnf:
sudo dnf install mycli -y
Installing on Arch Linux and Manjaro
On Arch-based distributions, install the package from the official community repository:
sudo pacman -S mycli
Alternative: Installing via pipx (Isolated Python Environment)
If you are using a distribution with strict PEP 668 package restrictions or require the newest upstream release, install mycli using pipx:
sudo apt install pipx -y # On Debian/Ubuntu
pipx ensurepath
pipx install mycli
Verify that the installation was successful by checking the installed version:
mycli --version
Step 2: Connect to a MySQL or MariaDB Database
mycli accepts the same standard connection parameters as the traditional mysql command-line utility, allowing a seamless transition for existing workflows.
Connecting as the Root User Locally
To connect to a local MySQL instance as the administrative user:
mycli -u root -p
Enter your database password when prompted. You will enter the interactive mycli prompt displaying your server version and connection details.
Connecting to a Specific Database
To directly open a specific database upon connecting, append the database name to the command:
mycli -u app_user -p -d production_db
Connecting to a Remote Database Host
Specify the remote hostname or IP address using the -h flag and an alternative port using -P if necessary:
mycli -h db.example.internal -P 3306 -u dbadmin -p -d analytics
Connecting Using a MySQL URI
mycli supports connection strings formatted as standard database URIs:
mycli mysql://dbadmin:[email protected]:3306/analytics
Step 3: Navigate and Query with Auto-Completion
Once connected, mycli automatically reads the schema metadata for the active database to power its suggestion engine.
Using Tab Completion for Keywords and Tables
Begin typing a standard SQL command such as SELECT * FROM . A popup menu appears listing available tables in the database. Use the arrow keys or press Tab to cycle through suggestions, and press Enter to select the desired table.
Filtering Column Names Dynamically
When drafting your column projection, such as SELECT u., mycli displays only the columns belonging to table alias u. This dynamic schema awareness eliminates syntax mistakes and speeds up query drafting significantly.
Multi-Line Query Drafting
To write queries spanning multiple lines, press Enter without appending a trailing semicolon (;). mycli moves the cursor to an indented new line, allowing you to structure complex JOIN and WHERE clauses cleanly. Terminate the query with a semicolon and press Enter to execute it.
Step 4: Customise mycli Configuration and Themes
When mycli is launched for the first time, it automatically generates a configuration file located at ~/.config/mycli/myclirc (or ~/.myclirc on older installations). You can edit this file to customise the visual layout, editing behaviour, and output formats.
Open the configuration file in your preferred text editor:
nano ~/.config/mycli/myclirc
Key Configuration Parameters
Customise the following directives according to your workflow requirements:
- syntax_style: Defines the syntax highlighting colour scheme. Popular values include
monokai,dracula,solarized-dark, andmanni. - table_format: Controls how query results are drawn. Options include
psql,fancy_grid,ascii,tsv, andcsv. - key_bindings: Set to
vito enable Vim-style modal navigation and editing commands, or leave asemacsfor standard readline shortcuts. - auto_vertical_output: Automatically switches long horizontal tables to vertical row-by-row views when the output width exceeds the terminal boundary.
- smart_completion: Enabled by default (
True); dynamically switches completion lists between keywords, functions, tables, and columns based on cursor placement.
Save and close the file. Changes take effect the next time you launch mycli.
Useful mycli Interactive Shortcuts
Inside the interactive prompt, mycli offers several helpful slash commands and hotkeys:
\?orhelp: Displays interactive commands and shortcut assistance.\dt: Lists all tables in the currently selected database.\d table_name: Describes columns and data types for the specified table.\T format: Temporarily changes the result table formatting style (for example,\T csvor\T ascii).- Ctrl + R: Initiates a reverse history search across previously executed queries.
exitor\q: Disconnects from the database server and returns to your system shell.