如何在 Linux(CentOS、Debian、 Fedora, 和 Ubuntu)

命令行界面 是一个 命令行 接口 MySQL, 玛丽亚数据库, 和 佩尔科纳自动完成 和语法高亮。 自动完成将帮助您更快、更轻松地编写查询。 REPL(读取、评估、打印、循环)将在您开始输入后立即弹出一个建议菜单。 这些建议是基于光标位置的上下文相关的。 例如:FROM 关键字后只建议表,WHERE 子句后只建议列名。

MyCLI 功能

在您键入 SQL 关键字以及数据库中的表、视图和列时自动完成。 打字时输入的语法高亮。 支持多行查询。 允许您保存您最喜欢的查询。 以吸引人的方式打印表格数据。 支持 SSL 连接。 智能完成(默认启用)将建议上下文相关的完成。 将每个查询及其结果记录到一个文件中。

如何在 Linux 中为 MySQL 和 MariaDB 安装 MyCLI

Debian/Ubuntu 分布,你可以很容易地 安装 MyCLI 包 使用 apt 命令。

$ sudo apt-get update $ sudo apt-get install mycli

Fedora 有一个可用于 MyCLI 的包。 使用 dnf 命令安装它,如下所示。

$ sudo dnf install mycli

对于其他 Linux 发行版,例如 RHEL/CentOS,您需要 Python pip 工具来安装 mycli。 首先使用以下命令安装 pip:

$ sudo yum install pip

安装 pip 后,您可以按如下方式安装 mycli:

$ sudo pip install mycli

如何在 Linux 中使用 MyCLI for MySQL 和 MariaDB

这是一个小演示:

如何使用 mycli 命令

要查看用法手册页,请使用以下命令:

# mycli  --help Usage: mycli [OPTIONS] [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   --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                 Version of mycli.   -D, --database TEXT           Database to use.   -R, --prompt TEXT             Prompt format (Default: "t [email protected]h:d> ")   -l, --logfile FILENAME        Log every query and its results to a file.   --defaults-group-suffix TEXT  Read config group with the specified suffix.   --defaults-file PATH          Only read default options from the given 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.   --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 query to the database.   --help                        Show this message and exit.

就这样! 在本指南中,我们展示了 如何安装和使用mycli 在 Linux 中使用简单的命令。 请通过下面的反馈表分享您对本文的想法。