Master MyCLI: A Powerful Python‑Based Interactive Database Client
This guide introduces MyCLI, a Python‑driven interactive command‑line client for databases, covering its key features, installation methods, configuration steps, connection commands, query execution, syntax‑highlighting options, and practical usage examples.
Introduction
MyCLI is a Python‑written command‑line tool that uses the prompt_toolkit library to build interactive CLI applications for interacting with various databases. It sits on Python’s DB‑API and provides shortcuts, auto‑completion, syntax highlighting, history, and export features.
Features
Auto‑completion : suggests tables, column names, keywords.
Syntax highlighting : colors SQL statements.
History : records all commands for reuse.
Keyboard shortcuts : e.g., Ctrl+R to search history, Ctrl+W to delete previous word.
Export : results can be saved as CSV, JSON, or HTML.
Installation and Configuration
Installation
apt-get install mycliOr install via Python’s package manager:
pip install mycliConfiguration
Before using MyCLI you must provide connection details, either on the command line or in a configuration file. The first run creates ~/.myclirc. MyCLI also reads the [client] section from MySQL’s config file.
Database Management
Connecting to a Database
mycli -h hostname -u username -p password -P port -D databaseExample output shows MySQL version, MyCLI version, and links to the home page and bug tracker.
Docker container connection
docker exec -it dnmp-mysql sh -c "export LANG=C.UTF-8 && mycli -h 127.0.0.1 -p123456"Executing SQL Queries
After a successful connection, type SQL statements and press Enter; results are displayed in a table.
Syntax Highlighting
If you get tired of the default theme, MyCLI provides several built‑in color schemes.
Open MyCLI configuration file
vim ~/.myclircOfficial color theme repository: https://www.mycli.net/syntax
Locate the syntax_style = default line and change it to the desired theme.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
