8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.5 客户端程序 / 6.5.1 mysql — MySQL 命令行客户端
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

6.5.1 mysql — MySQL 命令行客户端6.5.1 mysql — The MySQL Command-Line Client

mysql 是一个具有输入行编辑功能的简单 SQL 命令行工具。它支持交互式和非交互式使用。在交互式使用时,查询结果以 ASCII 表格格式显示。在非交互式使用时(例如,作为过滤器),结果以制表符分隔格式显示。输出格式可以通过命令选项进行更改。mysql is a simple SQL shell with input line editing capabilities. It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format. When used noninteractively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.

如果由于大型结果集导致内存不足而出现问题,请使用 --quick 选项。此选项会强制 mysql 一次从服务器检索一行结果,而不是在显示之前将整个结果集检索到内存中并缓冲。通过客户端/服务器库中的 mysql_use_result() C API 函数返回结果集,而不是使用 mysql_store_result()。If you have problems due to insufficient memory for large result sets, use the --quick option. This forces mysql to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it. This is done by returning the result set using the mysql_use_result() C API function in the client/server library rather than mysql_store_result().

Note

或者,MySQL Shell 提供对 X DevAPI 的访问。有关详细信息,请参阅 MySQL Shell 8.4。Alternatively, MySQL Shell offers access to the X DevAPI. For details, see MySQL Shell 8.4.

使用 mysql 非常简单。从命令解释器的提示符调用它,如下所示:Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:

mysql db_name

或者:Or:

mysql --user=user_name --password db_name

在这种情况下,您需要在 mysql 显示提示时输入密码:In this case, you'll need to enter your password in response to the prompt that mysql displays:

Enter password: your_password

然后键入 SQL 语句,以 ;、\g 或 \G 结尾,然后按 Enter。Then type an SQL statement, end it with ;, \g, or \G and press Enter.

按下 Control+C 会中断当前语句(如果有的话),否则会取消任何部分输入的行。Typing Control+C interrupts the current statement if there is one, or cancels any partial input line otherwise.

你可以像这样在脚本文件(批处理文件)中执行 SQL 语句:You can execute SQL statements in a script file (batch file) like this:

mysql db_name < script.sql > output.tab

在 Unix 系统上,mysql 客户端会将交互执行的语句记录到历史文件中。参见 第 6.5.1.3 节,“mysql 客户端日志记录”。On Unix, the mysql client logs statements executed interactively to a history file. See Section 6.5.1.3, “mysql Client Logging”.