SysTutorials

Linux Manual Pages › Section 1

mysql_embedded(1)

NAME

mysql – the MySQL command-line client

SYNOPSIS

mysql [options] db_name

DESCRIPTION

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.

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

Alternatively, MySQL Shell offers access to the X DevAPI. For details, see m[blue]MySQL Shell 8.0 (part of MySQL 8.0)m[][1].

Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:

shell> mysql db_name

Or:

shell> mysql --user=user_name --password db_name
Enter password: your_password

Then type an SQL statement, end it with ;, \g, or \G and press Enter.

Typing Control+C interrupts the current statement if there is one, or cancels any partial input line otherwise.

You can execute SQL statements in a script file (batch file) like this:

shell> mysql db_name < script.sql > output.tab

On Unix, the mysql client logs statements executed interactively to a history file. See the section called “MYSQL CLIENT LOGGING”.

MYSQL CLIENT OPTIONS

mysql supports the following options, which can be specified on the command line or in the [mysql] and [client] groups of an option file. For information about option files used by MySQL programs, see Section 4.2.2.2, “Using Option Files”.

• –help, -?

Display a help message and exit.

• –auto-rehash

Enable automatic rehashing. This option is on by default, which enables database, table, and column name completion. Use –disable-auto-rehash to disable rehashing. That causes mysql to start faster, but you must issue the rehash command or its \# shortcut if you want to use name completion.

To complete a name, enter the first part and press Tab. If the name is unambiguous, mysql completes it. Otherwise, you can press Tab again to see the possible names that begin with what you have typed so far. Completion does not occur if there is no default database.

Note
This feature requires a MySQL client that is compiled with the readline library. Typically, the readline library is not available on Windows.
• –auto-vertical-output

Cause result sets to be displayed vertically if they are too wide for the current window, and using normal tabular format otherwise. (This applies to statements terminated by ; or \G.)

• –batch, -B

Print results using tab as the column separator, with each row on a new line. With this option, mysql does not use the history file.

Batch mode results in nontabular output format and escaping of special characters. Escaping may be disabled by using raw mode; see the description for the –raw option.

• –binary-as-hex

When this option is given, mysql displays binary data using hexadecimal notation (0xvalue). This occurs whether the overall output dislay format is tabular, vertical, HTML, or XML.

This option was added in MySQL 5.7.19.

• –binary-mode

This option helps when processing mysqlbinlog output that may contain BLOB values. By default, mysql translates in statement strings to and interprets