mysql is a simple SQL shell with input line editing capabilities. It supports interactive and noninteractive use. mysql是一个简单的SQL shell,具有输入行编辑功能。它支持交互式和非交互式使用。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. 交互使用时,查询结果以ASCII表格式显示。当非交互式使用时(例如,作为筛选器),结果以制表符分隔的格式显示。The output format can be changed using command options.可以使用命令选项更改输出格式。
If you have problems due to insufficient memory for large result sets, use the 如果由于大型结果集内存不足而出现问题,请使用--quick
option. --quick
选项。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. 这迫使mysql一次从服务器检索一行结果,而不是检索整个结果集并在显示之前将其缓冲在内存中。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_use_result()
C API函数而不是mysql_store_result()
返回结果集来完成的。
Alternatively, MySQL Shell offers access to the X DevAPI. For details, see MySQL Shell 8.0.或者,MySQL Shell提供对X DevAPI的访问。有关详细信息,请参阅MySQL Shell 8.0。
Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:使用mysql非常简单。从命令解释器的提示符调用它,如下所示:
mysql db_name
Or:
mysql --user=user_name
--passworddb_name
In this case, you'll need to enter your password in response to the prompt that mysql displays:在这种情况下,您需要输入密码以响应mysql显示的提示:
Enter password:输入密码:your_password
Then type an SQL statement, end it with 然后键入一个SQL语句,以结尾;
, \g
, or \G
and press Enter.;
、\g
或\G
,然后按Enter键。
Typing Control+C interrupts the current statement if there is one, or cancels any partial input line otherwise.键入Control+C会中断当前语句(如果有),否则会取消任何部分输入行。
You can execute SQL statements in a script file (batch file) like this:您可以在脚本文件(批处理文件)中执行SQL语句,如下所示:
mysqldb_name
<script.sql
>output.tab
On Unix, the mysql client logs statements executed interactively to a history file. See Section 4.5.1.3, “mysql Client Logging”.在Unix上,mysql客户端将交互式执行的语句记录到历史文件中。请参阅第4.5.1.3节,“mysql客户端日志记录”。