Scripts2026年4月15日·1 分钟阅读

mycli — MySQL CLI with Auto-Completion and Syntax Highlighting

mycli is a Python-based interactive CLI for MySQL/MariaDB/Percona with smart auto-completion, syntax highlighting, and result formatting — sister project to pgcli.

Introduction

mysql CLI works, but its readline bindings feel primitive next to a modern IDE console. mycli closes the gap: aware of table and column names, colored SQL, parameter placeholders, and friendly result formatting. Connects to MySQL, MariaDB, Percona, TiDB, CockroachDB (via MySQL protocol), PlanetScale.

What mycli Does

  • Interactive REPL for MySQL-compatible databases.
  • Context-aware completion from live schema.
  • Syntax-highlighted input.
  • Pretty tables with G vertical toggle.
  • Named queries, favorites, connection profiles.

Architecture Overview

mycli uses PyMySQL for connectivity and prompt-toolkit for the REPL. Schema introspection populates completion tries. Syntax highlighting via Pygments. Output formatting via cli-helpers. Configuration mirrors pgcli's ~/.myclirc.

Self-Hosting & Configuration

  • Install via pip, brew, apt, dnf.
  • ~/.myclirc stores defaults: pager, vertical threshold, warn-on-destructive.
  • SSH tunnel: --ssh-host bastion --ssh-user op.
  • Auto-vertical when row width > terminal.
  • destructive_warning = true asks before DELETE/UPDATE without WHERE.

Key Features

  • Smart completion with JOIN help.
  • Pager integration.
  • Multiline editor (vi/emacs keybindings).
  • Connection multiplexer — switch DBs with .
  • Safer than stock client with destructive-warning flag.

Comparison with Similar Tools

  • mysql — stock client; universal, basic.
  • pgcli — same pattern for PostgreSQL.
  • mysqlsh — official Python/JS shell; heavier.
  • dbeaver — GUI.
  • usql — multi-DB CLI.

FAQ

Q: Works with TiDB/MariaDB? A: Yes — MySQL protocol-compatible.

Q: Safer deletes? A: destructive_warning = true prompts when WHERE is missing.

Q: Export CSV? A: T csv then run query.

Q: Password auth? A: Set MYSQL_PWD or use --login-path for mysql_config_editor files.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产