4.5.1 mysql — The MySQL Command-Line ClientMySQL命令行客户端

4.5.1.1 mysql Client Optionsmysql客户端选项
4.5.1.2 mysql Client Commandsmysql客户端命令
4.5.1.3 mysql Client Loggingmysql客户端日志记录
4.5.1.4 mysql Client Server-Side Helpmysql客户端服务器端帮助
4.5.1.5 Executing SQL Statements from a Text File从文本文件执行SQL语句
4.5.1.6 mysql Client Tipsmysql客户端提示

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()返回结果集来完成的。

Note注意

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 --password db_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 ;, \g, or \G and press Enter.然后键入一个SQL语句,以结尾;\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语句,如下所示:

mysql db_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客户端日志记录”

4.5.1.1 mysql Client Options
4.5.1.2 mysql Client Commands
4.5.1.3 mysql Client Logging
4.5.1.4 mysql Client Server-Side Help
4.5.1.5 Executing SQL Statements from a Text File
4.5.1.6 mysql Client Tips