MyCLI

一个具有自动完成和语法高亮功能的 MySQL 终端客户端。「A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.」

Github stars Tracking Chart

mycli

MySQL 的命令行客户端,可以进行自动完成和语法高亮显示。

主页:http://mycli.net;文档:http://mycli.net/docs

Postgres 等价物:http://pgcli.com

快速入门

如果你已经知道如何安装 python 包,那么你可以通过 pip 安装。

在 Linux 上你可能需要 sudo。

$ pip install -U mycli

或者

$ brew update && brew install mycli  # 仅用于 macOS

或者

$ sudo apt-get install mycli # 仅用于 debian 或 ubuntu

用法

$ mycli --help
Usage: mycli [OPTIONS] [DATABASE]
  A MySQL terminal client with auto-completion and syntax highlighting.
  Examples:
    - mycli my_database
    - mycli -u my_user -h my_host.com my_database
    - mycli mysql://my_user@my_host.com:3306/my_database
Options:
  -h, --host TEXT               Host address of the database.
  -P, --port INTEGER            Port number to use for connection. Honors
                                $MYSQL_TCP_PORT.
  -u, --user TEXT               User name to connect to the database.
  -S, --socket TEXT             The socket file to use for connection.
  -p, --password TEXT           Password to connect to the database.
  --pass TEXT                   Password to connect to the database.
  --ssh-user TEXT               User name to connect to ssh server.
  --ssh-host TEXT               Host name to connect to ssh server.
  --ssh-port INTEGER            Port to connect to ssh server.
  --ssh-password TEXT           Password to connect to ssh server.
  --ssh-key-filename TEXT       Private key filename (identify file) for the
                                ssh connection.
  --ssh-config-path TEXT        Path to ssh configuation.
  --ssh-config-host TEXT        Host for ssh server in ssh configuations (requires paramiko).
  --ssl-ca PATH                 CA file in PEM format.
  --ssl-capath TEXT             CA directory.
  --ssl-cert PATH               X509 cert in PEM format.
  --ssl-key PATH                X509 key in PEM format.
  --ssl-cipher TEXT             SSL cipher to use.
  --ssl-verify-server-cert      Verify server's "Common Name" in its cert
                                against hostname used when connecting. This
                                option is disabled by default.
  -V, --version                 Output mycli's version.
  -v, --verbose                 Verbose output.
  -D, --database TEXT           Database to use.
  -d, --dsn TEXT                Use DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-dsn                    list of DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-ssh-config             list ssh configurations in the ssh config (requires paramiko).
  -R, --prompt TEXT             Prompt format (Default: "\t \u@\h:\d> ").
  -l, --logfile FILENAME        Log every query and its results to a file.
  --defaults-group-suffix TEXT  Read MySQL config groups with the specified
                                suffix.
  --defaults-file PATH          Only read MySQL options from the given file.
  --myclirc PATH                Location of myclirc file.
  --auto-vertical-output        Automatically switch to vertical output mode
                                if the result is wider than the terminal
                                width.
  -t, --table                   Display batch output in table format.
  --csv                         Display batch output in CSV format.
  --warn / --no-warn            Warn before running a destructive query.
  --local-infile BOOLEAN        Enable/disable LOAD DATA LOCAL INFILE.
  --login-path TEXT             Read this path from the login file.
  -e, --execute TEXT            Execute command and quit.
  --init-command TEXT           SQL statement to execute after connecting.
  --help                        Show this message and exit.

特性

mycli 是使用 prompt_toolkit 编写的。

  • 当您键入 SQL 关键字以及数据库中的表、视图和列时,自动完成。
  • 使用 Pygments 的语法高亮显示。
  • 智能补全(默认情况下启用)将建议使用上下文敏感的补全方式。
  • SELECT * FROM <tab>将只显示表名。
  • SELECT * FROM users WHERE <tab>将只显示列名。
  • 支持多行查询。
  • 可选位置参数的收藏夹查询。使用 \fs alias query 保存查询,并在需要时使用 \f alias 执行。
  • sql 状态和表渲染的定时。
  • 配置文件在第一次启动时自动创建在 ~/.myclirc。
  • 将每个查询及其结果记录到文件中(默认情况下是禁用的)。
  • 漂亮地打印表格数据(带颜色!)。
  • 支持 SSL 连接

贡献

如果你有兴趣为这个项目做贡献,首先我想表达我由衷的感谢。我已经写了一个小文档来描述如何在开发设置中运行这个项目。

https://github.com/dbcli/mycli/blob/master/CONTRIBUTING.md

如果你需要帮助,请随时联系我。

我的邮箱:amjith.r@gmail.com

Twitter: @amjithr

详细安装说明

Fedora

Fedora 有一个 mycli 的软件包,使用 dnf 安装它。

$ sudo dnf install mycli

RHEL, Centos

我还没有为 mycli 建立一个 RHEL 或 Centos 的 RPM 包。所以请使用 pip 来安装 mycli。你可以在你的系统上安装 pip,使用

$ sudo yum install python-pip

安装完毕后,你可以按照以下方式安装 mycli。

$ sudo pip install mycli

Windows

按照本博文的说明:https://www.codewall.co.uk/installing-using-mycli-on-windows/

Cygwin

确保安装了以下 Cygwin 包:python3、python3-pip。

安装mycli: pip3 install mycli

谢谢

这个项目是通过 kickstarter 资助的 我感谢支持该项目的支持者

特别感谢 Jonathan Slenders 创建了 Python Prompt Toolkit,它实际上是骨干库,使这个应用成为可能。Jonathan 在这个应用的开发过程中也提供了宝贵的反馈和支持。

Click 用于命令行选项解析和打印错误信息。

感谢 PyMysql 为 MySQL 数据库提供的纯 Python 适配器。

兼容性

Mycli 在 macOS 和 Linux 上进行了测试。

Mycli 没有在 Windows 上进行测试,但该应用程序中使用的库是与 Windows 兼容的。这意味着它应该不需要任何修改就能运行。如果您无法在 Windows 上运行它,请提交一个错误

配置和使用

关于使用和配置 mycli 的更多信息,请查看我们的文档

常见的主题包括


(The first version translated by vz on 2020.09.26)

Overview

Name With Ownerdbcli/mycli
Primary LanguagePython
Program languagePython (Language Count: 2)
PlatformLinux, Mac, Windows
License:Other
Release Count51
Last Release Namev1.27.2 (Posted on )
First Release Namev1.0.0 (Posted on )
Created At2015-04-05 22:39:49
Pushed At2024-05-11 14:55:24
Last Commit At2022-03-29 17:27:34
Stargazers Count11.3k
Watchers Count187
Fork Count652
Commits Count1.9k
Has Issues Enabled
Issues Count656
Issue Open Count202
Pull Requests Count440
Pull Requests Open Count6
Pull Requests Close Count55
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

mycli

Build Status
PyPI
Join the chat at https://gitter.im/dbcli/mycli

A command line client for MySQL that can do auto-completion and syntax highlighting.

HomePage: http://mycli.net
Documentation: http://mycli.net/docs

Completion
CompletionGif

Postgres Equivalent: http://pgcli.com

Quick Start

If you already know how to install python packages, then you can install it via pip:

You might need sudo on linux.

$ pip install -U mycli

or

$ brew update && brew install mycli  # Only on macOS

or

$ sudo apt-get install mycli # Only on debian or ubuntu

Usage

$ mycli --help
Usage: mycli [OPTIONS] [DATABASE]

  A MySQL terminal client with auto-completion and syntax highlighting.

  Examples:
    - mycli my_database
    - mycli -u my_user -h my_host.com my_database
    - mycli mysql://my_user@my_host.com:3306/my_database

Options:
  -h, --host TEXT               Host address of the database.
  -P, --port INTEGER            Port number to use for connection. Honors
                                $MYSQL_TCP_PORT.
  -u, --user TEXT               User name to connect to the database.
  -S, --socket TEXT             The socket file to use for connection.
  -p, --password TEXT           Password to connect to the database.
  --pass TEXT                   Password to connect to the database.
  --ssh-user TEXT               User name to connect to ssh server.
  --ssh-host TEXT               Host name to connect to ssh server.
  --ssh-port INTEGER            Port to connect to ssh server.
  --ssh-password TEXT           Password to connect to ssh server.
  --ssh-key-filename TEXT       Private key filename (identify file) for the
                                ssh connection.
  --ssl-ca PATH                 CA file in PEM format.
  --ssl-capath TEXT             CA directory.
  --ssl-cert PATH               X509 cert in PEM format.
  --ssl-key PATH                X509 key in PEM format.
  --ssl-cipher TEXT             SSL cipher to use.
  --ssl-verify-server-cert      Verify server's "Common Name" in its cert
                                against hostname used when connecting. This
                                option is disabled by default.
  -V, --version                 Output mycli's version.
  -v, --verbose                 Verbose output.
  -D, --database TEXT           Database to use.
  -d, --dsn TEXT                Use DSN configured into the [alias_dsn]
                                section of myclirc file.
  --list-dsn                    list of DSN configured into the [alias_dsn]
                                section of myclirc file.
  -R, --prompt TEXT             Prompt format (Default: "\t \u@\h:\d> ").
  -l, --logfile FILENAME        Log every query and its results to a file.
  --defaults-group-suffix TEXT  Read MySQL config groups with the specified
                                suffix.
  --defaults-file PATH          Only read MySQL options from the given file.
  --myclirc PATH                Location of myclirc file.
  --auto-vertical-output        Automatically switch to vertical output mode
                                if the result is wider than the terminal
                                width.
  -t, --table                   Display batch output in table format.
  --csv                         Display batch output in CSV format.
  --warn / --no-warn            Warn before running a destructive query.
  --local-infile BOOLEAN        Enable/disable LOAD DATA LOCAL INFILE.
  --login-path TEXT             Read this path from the login file.
  -e, --execute TEXT            Execute command and quit.
  --help                        Show this message and exit.

Features

mycli is written using prompt_toolkit.

  • Auto-completion as you type for SQL keywords as well as tables, views and
    columns in the database.
  • Syntax highlighting using Pygments.
  • Smart-completion (enabled by default) will suggest context-sensitive completion.
    • SELECT * FROM <tab> will only show table names.
    • SELECT * FROM users WHERE <tab> will only show column names.
  • Support for multiline queries.
  • Favorite queries with optional positional parameters. Save a query using
    \fs alias query and execute it with \f alias whenever you need.
  • Timing of sql statments and table rendering.
  • Config file is automatically created at ~/.myclirc at first launch.
  • Log every query and its results to a file (disabled by default).
  • Pretty prints tabular data (with colors!)
  • Support for SSL connections

Contributions:

If you're interested in contributing to this project, first of all I would like
to extend my heartfelt gratitude. I've written a small doc to describe how to
get this running in a development setup.

https://github.com/dbcli/mycli/blob/master/CONTRIBUTING.md

Please feel free to reach out to me if you need help.

My email: amjith.r@gmail.com

Twitter: @amjithr

Detailed Install Instructions:

Fedora

Fedora has a package available for mycli, install it using dnf:

$ sudo dnf install mycli

RHEL, Centos

I haven't built an RPM package for mycli for RHEL or Centos yet. So please use pip to install mycli. You can install pip on your system using:

$ sudo yum install python-pip

Once that is installed, you can install mycli as follows:

$ sudo pip install mycli

Windows

Follow the instructions on this blogpost: https://www.codewall.co.uk/installing-using-mycli-on-windows/

Cygwin

  1. Make sure the following Cygwin packages are installed:
    python3, python3-pip.
  2. Install mycli: pip3 install mycli

Thanks:

This project was funded through kickstarter. My thanks to the backers who supported the project.

A special thanks to Jonathan Slenders for
creating Python Prompt Toolkit,
which is quite literally the backbone library, that made this app possible.
Jonathan has also provided valuable feedback and support during the development
of this app.

Click is used for command line option parsing
and printing error messages.

Thanks to PyMysql for a pure python adapter to MySQL database.

Compatibility

Mycli is tested on macOS and Linux.

Mycli is not tested on Windows, but the libraries used in this app are Windows-compatible.
This means it should work without any modifications. If you're unable to run it
on Windows, please file a bug.

Configuration and Usage

For more information on using and configuring mycli, check out our documentation.

Common topics include:

To the top