MyCLI - CLI for MySQL Database
mycli is an interactive command-line client for MySQL, MariaDB, and Percona databases, featuring auto-completion, syntax highlighting, and smart suggestions. It's built on prompt_toolkit and pygments, providing a user-friendly and efficient interface for database administration and querying. The current version is 1.68.1, with a release cadence of minor versions every few weeks to months.
Common errors
-
mycli: command not found
cause The `mycli` executable is either not installed or its installation directory is not included in your system's PATH environment variable.fixEnsure MyCLI is installed (`pip install mycli`). If installed but still not found, check your Python installation's `Scripts` or `bin` directory (e.g., `~/.local/bin` on Linux/macOS) and add it to your PATH, or use `python -m mycli` if available. -
ERROR 1045 (28000): Access denied for user 'youruser'@'localhost' (using password: NO)
cause This is a standard MySQL access denied error. It means the username, password, or host you provided (or defaulted to) is incorrect, or the user lacks privileges to connect from your host.fixDouble-check your username (`-u`), password (`-p`, MyCLI will prompt if not provided), and host (`-h`). Ensure the MySQL user has privileges to connect from the client's IP address or hostname. -
No module named 'mycli'
cause You are trying to import `mycli` as a Python module in a script, but `mycli` is designed as a command-line application, not a library for direct programmatic import of its core functionality.fixDo not attempt to `import mycli`. Instead, execute `mycli` directly from your shell. If you need to automate database tasks, consider using a database connector library like `mysql-connector-python` or `PyMySQL`.
Warnings
- deprecated The environment variable `$MYSQL_UNIX_PORT` has been deprecated. While it may still work, it is recommended to use standard MySQL client configuration methods or command-line flags for specifying the UNIX socket.
- gotcha The `--throttle` command-line option, used for limiting query execution rate in batch mode, changed its expected argument type from an integer to a float.
- gotcha MyCLI has frequent updates to its `sqlglot` dependency, sometimes requiring specific minor versions or C extensions. This can occasionally lead to installation failures or runtime issues if dependency conflicts arise or if the C extensions fail to compile.
Install
-
pip install mycli
Imports
- mycli
mycli
Quickstart
# To connect to a local MySQL instance as root: mycli -u root # To connect to a specific database (e.g., 'testdb') on a remote host (e.g., '192.168.1.100'): mycli -h 192.168.1.100 -u myuser -D testdb -p # To exit the mycli prompt: # \q # (or Ctrl+D)