- 6.5.1.1 mysql 客户端选项6.5.1.1 mysql Client Options
- 6.5.1.2 mysql 客户端命令6.5.1.2 mysql Client Commands
- 6.5.1.3 mysql 客户端日志6.5.1.3 mysql Client Logging
- 6.5.1.4 mysql 客户端服务器端帮助6.5.1.4 mysql Client Server-Side Help
- 6.5.1.5 从文本文件执行 SQL 语句6.5.1.5 Executing SQL Statements from a Text File
- 6.5.1.6 mysql 客户端技巧6.5.1.6 mysql Client Tips
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().
或者,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--passworddb_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:
mysqldb_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”.