文章目录

mycli is a feature-rich command-line client for MySQL and its compatible databases (MariaDB, Percona, TiDB), currently with around 11,900 GitHub stars. Built and maintained by the dbcli team, it brings intelligent auto-completion, syntax highlighting, and smart context-aware suggestions to the terminal-based database workflow. For developers and DBAs who spend significant time writing SQL queries from the command line, mycli transforms a blunt tool into something genuinely enjoyable to use.

The standard mysql CLI client is functional but spartan — no syntax coloring, no intelligent completion, and a completely flat output format. mycli addresses all of these pain points with a modern terminal interface built on Python Prompt Toolkit. Having used both extensively, the auto-completion alone is a productivity multiplier: typing SELECT * FROM users WHERE and seeing only the column names from that table appear in the completion menu saves constant context-switching to documentation or separate DESCRIBE queries.

What I find particularly impressive is the fuzzy history search powered by fzf integration. If you vaguely remember running a query last week but cannot recall the exact syntax, a quick fuzzy search through your history surfaces it instantly. The favorite queries feature (\fs alias query) is equally useful for recurring analytical queries that you tune over time. The project also recently added LLM integration — you can query an LLM with context derived from your database schema, which is a genuinely novel feature for a CLI tool.

mycli works with MySQL, MariaDB, Percona, and TiDB out of the box. Installation is straightforward via pip, Homebrew, or apt — pip install -U 'mycli[all]' gets you everything including optional dependencies. The project leverages Prompt Toolkit for the UI, Pygments for syntax highlighting, and supports multiline query editing, SSL connections, and shell-style redirects ($>, $>>, $|). The config file ~/.myclirc generated on first run exposes dozens of customization options, from completion settings to theme colors.

One noteworthy recent addition is the LLM query support — you can ask natural language questions about your data with context injected from your schema. This bridges the gap between exploratory SQL work and conversational AI assistance without leaving the terminal.

Daily development work: If you are constantly running ad-hoc queries against a local or remote MySQL database during development, mycli's smart completion makes the workflow significantly faster than the vanilla mysql client. The table and column name completion alone justifies the switch.

Database administration and debugging: DBAs who diagnose slow queries or audit data can save frequently used diagnostic queries as favorites and execute them with a single command. The timing information displayed after each query execution is helpful for identifying performance bottlenecks.

Cross-database exploration: When working across multiple MySQL-compatible databases (e.g., switching between a local MariaDB and a production Percona instance), mycli's consistent interface and SSL support make the transition seamless without re-learning keyboard shortcuts.

Step 1: Install mycli

pip install -U 'mycli[all]'

Step 2: Connect to your database

mycli -u root -h localhost myappdb

Step 3: Try auto-completion

SELECT * FROM orders WHERE status = 'pending'
# Type "orders." and watch table columns appear

Step 4: Search history with fuzzy matching

\f pending orders
# Use fzf-powered fuzzy search to find past queries

Step 5: Save a favorite query

\fs slow_users SELECT u.*, COUNT(o.id) as order_count
  FROM users u LEFT JOIN orders o ON u.id = o.user_id
  GROUP BY u.id HAVING order_count > 10

# Execute it later with:
\f slow_users

  • Smart context-aware completion: Unlike basic auto-complete tools, mycli understands SQL context. SELECT * FROM triggers table completion; WHERE triggers column completion. This reduces cognitive load significantly during exploratory queries on unfamiliar schemas.
  • Multi-database compatibility: mycli works identically across MySQL, MariaDB, Percona, and TiDB, making it a portable tool for teams with heterogeneous database infrastructure. SSL connections are supported out of the box.
  • LLM integration: The recently added LLM query feature lets you ask natural language questions about your data with automatic schema context injection. This is particularly useful during the early stages of exploring an unfamiliar database.

Star trend: ⭐ 11.9k | 📈 +15 today (estimated)

Compared to the standard mysql CLI, mycli is a significant upgrade in terms of usability and visual clarity. Compared to phpMyAdmin or Adminer (web-based tools), mycli stays entirely in the terminal — no browser overhead, works over SSH tunnels without exposing web interfaces. Compared to DBeaver (GUI), mycli is faster to launch, uses far less memory, and integrates naturally into terminal-based workflows. If you prefer GUI tools for complex schema visualization, DBeaver wins; for daily SQL work in a terminal, mycli is the better choice.

Issue #361 — Testing mycli with pexpect (67 comments): A long-running discussion about adding pexpect-based integration tests to cover the TTY code paths. This is a technically challenging area because CLI tools that manage terminal state (prompt_toolkit, readline) are notoriously hard to test end-to-end. The community debated test infrastructure approaches for years before a workable solution emerged, demonstrating the dbcli team's commitment to long-term code quality.

Issue #1165 — Better sorting of completions (42 comments): A user requested improving the completion sorting algorithm to rank matches by relevance rather than alphabetically. The discussion involved match point scoring, match length weighting, and text length considerations. The PR that followed became one of the most appreciated contributions, significantly improving the UX of auto-completion in everyday use.

Issue #102 — pip install on Linux Python 2.6 error (30 comments): An early issue from 2014 where a user encountered a SyntaxError on Python 2.6 due to dictionary comprehension syntax ({x: get(x) for x in keys}). This was a useful historical record showing how mycli evolved alongside Python's own evolution from 2.x to 3.x, eventually dropping Python 2 support entirely.

  • Password storage: mycli supports storing passwords in the system keyring (via the optional [all] extras). On shared systems, avoid this if security policies prohibit credential caching — instead use mycli --prompt 'login:@host> ' to keep connections explicit.
  • Multiline query mode: Multiline queries require a semicolon to execute. If your query seems to hang, check that you have not forgotten the terminating semicolon — the prompt_toolkit interface does not show a clear "waiting for input" indicator for unclosed statements.
  • Large result sets: mycli pretty-prints results with colors, which is great for small to medium datasets. For multi-million row exports, pipe output to a file with $> output.csv or use the \T output redirection command to avoid performance degradation from rendering thousands of colored rows.

mycli is one of those tools that feels obvious in retrospect — of course your MySQL CLI should highlight syntax and auto-complete table names. The dbcli team has maintained this project for over a decade, consistently adding thoughtful features like fuzzy history search, favorite queries, and even LLM integration. If you work with MySQL from the command line regularly and have been tolerating the bare-bones mysql client out of habit, mycli is a genuinely satisfying upgrade that pays dividends in daily productivity. It is lightweight, well-documented, and available in every major package manager.

Project Links:

🔗 More GitHub Trending Open Source Projects: Developer Tools