mycli
Connect to and execute SQL queries
TLDR
Connect to a local database on port 3306, using the current user's username
Connect to a database (user will be prompted for a password)
Connect to a database on another host
SYNOPSIS
mycli [OPTIONS] [DATABASE_NAME_OR_URL]
Connects to a database using provided credentials or a connection URL.
PARAMETERS
-h, --host
Connect to MySQL or PostgreSQL on the specified host.
-u, --user
User for login if not current user.
-p, --password[=
Password to use when connecting to the database. If omitted, prompts for password.
-P, --port
TCP/IP port number to use for the connection.
-D, --database
Database to use after connecting. Can also be specified as an argument without the flag.
--ssl-ca
CA file in PEM format for SSL connection.
--ssl-cert
X.509 certificate in PEM format for SSL connection.
--ssl-key
X.509 key in PEM format for SSL connection.
--auto-vertical-output
Automatically switch to vertical output mode if the result is too wide.
--pager
Specify a pager command to use for results (e.g., 'less -S').
--editor
Open the default text editor for multi-line queries.
--config
Specify an alternative configuration file path.
--version
Show program's version number and exit.
--help
Show a help message and exit.
DESCRIPTION
mycli is a powerful, user-friendly command-line interface for popular relational databases including MySQL, PostgreSQL, and SQLite. Developed as a modern alternative to traditional database clients, it significantly enhances the terminal-based database interaction experience. Its standout features include robust auto-completion, which intelligently suggests SQL keywords, table names, column names, and view names as you type, making query construction faster and less error-prone. Additionally, mycli provides beautiful syntax highlighting for all SQL queries, greatly improving readability and aiding in the identification of syntax errors.
Beyond these core features, mycli offers smart auto-completion that understands the context of your query, support for pagers to handle large result sets efficiently, and the ability to connect securely using SSL/TLS. It is built upon the prompt_toolkit library for its rich interactive features and Pygments for syntax highlighting, ensuring a highly responsive and visually appealing interface. mycli is a valuable tool for developers, database administrators, and anyone who frequently interacts with these databases from the command line, transforming a often cumbersome task into a more streamlined and enjoyable workflow.
CAVEATS
While mycli offers a superior interactive experience, it is not a full replacement for every advanced feature found in native clients like mysql or psql, particularly those related to specific administrative utilities or highly specialized commands (e.g., data dumping, binary log analysis). It primarily focuses on query execution and data interaction. Also, being Python-based, it requires a Python installation to run.
CONFIGURATION FILE
mycli can be extensively customized via a configuration file, typically located at ~/.myclirc. This file allows users to define settings such as key bindings, color themes, pager options, and various behavioral preferences, tailoring the CLI experience to individual needs.
CONNECTION STRING
Beyond standard host, user, and password parameters, mycli supports connecting to databases using a comprehensive URL connection string. This format allows for a single, concise argument to specify all connection details, including username, password, host, port, database, and even SSL parameters, making it convenient for scripting or quick connections.
Example: mycli mysql://user:pass@host:3306/dbname?sslmode=require
HISTORY
mycli was created by Amjith Ramanujam and first released in 2015. It quickly gained traction as a more modern and user-friendly alternative to traditional database command-line clients. It is built upon the robust Python ecosystem, leveraging libraries like prompt_toolkit for its advanced terminal interaction features and Pygments for syntax highlighting. mycli is part of a family of similarly designed command-line tools, including pgcli for PostgreSQL, which share a common architectural philosophy focused on user experience and productivity. Its development was driven by the desire to bring features common in modern IDEs (like auto-completion and syntax highlighting) directly to the command line for database interactions.