Where is Mysql_config_editor file?

This chapter provides a brief overview of the MySQL command-line programs provided by Oracle Corporation. It also discusses the general syntax for specifying options when you run these programs. Most programs have options that are specific to their own operation, but the option syntax is similar for all of them. Finally, the chapter provides more detailed descriptions of individual programs, including which options they recognize.

Show

4.1. Overview of MySQL Programs

There are many different programs in a MySQL installation. This section provides a brief overview of them. Later sections provide a more detailed description of each one. Each program's description indicates its invocation syntax and the options that it supports.

Most MySQL distributions include all of these programs, except for those programs that are platform-specific. (For example, the server startup scripts are not used on Windows.) The exception is that RPM distributions are more specialized. There is one RPM for the server, another for client programs, and so forth. If you appear to be missing one or more programs, see Chapter 2, Installing and Upgrading MySQL, for information on types of distributions and what they contain. It may be that you have a distribution that does not include all programs and you need to install an additional package.

Each MySQL program takes many different options. Most programs provide a

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
50 option that you can use to get a description of the program's different options. For example, try .

You can override default option values for MySQL programs by specifying options on the command line or in an option file. See , for general information on invoking programs and specifying program options.

The MySQL server, , is the main program that does most of the work in a MySQL installation. The server is accompanied by several related scripts that assist you in starting and stopping the server:

Several programs perform setup operations during MySQL installation or upgrading:

MySQL client programs that connect to the MySQL server:

MySQL administrative and utility programs:

MySQL program-development utilities:

Miscellaneous utilities:

Oracle Corporation also provides the MySQL Workbench GUI tool, which is used to administer MySQL servers and databases, to create, execute, and evaluate queries, and to migrate schemas and data from other relational database management systems for use with MySQL. Additional GUI tools include and MySQL for Excel.

MySQL client programs that communicate with the server using the MySQL client/server library use the following environment variables.

Environment VariableMeaning

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
51The default Unix socket file; used for connections to
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
53The default port number; used for TCP/IP connections
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
54The default password
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
55Debug trace options when debugging
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56The directory where temporary tables and files are created

For a full list of environment variables used by MySQL programs, see .

Use of

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
54 is insecure. See .

4.2. Using MySQL Programs

4.2.1. Invoking MySQL Programs

To invoke a MySQL program from the command line (that is, from your shell or command prompt), enter the program name followed by any options or other arguments needed to instruct the program what you want it to do. The following commands show some sample program invocations. “

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
58” represents the prompt for your command interpreter; it is not part of what you type. The particular prompt you see depends on your command interpreter. Typical prompts are
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
59 for sh, ksh, or bash,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
60 for csh or tcsh, and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
61 for the Windows command.com or cmd.exe command interpreters.

shell> mysql --user=root test
shell> mysqladmin extended-status variables
shell> mysqlshow --help
shell> mysqldump -u root personnel

Arguments that begin with a single or double dash (“

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
62”, “
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
63”) specify program options. Options typically indicate the type of connection a program should make to the server or affect its operational mode. Option syntax is described in .

Nonoption arguments (arguments with no leading dash) provide additional information to the program. For example, the program interprets the first nonoption argument as a database name, so the command

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
64 indicates that you want to use the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
65 database.

Later sections that describe individual programs indicate which options a program supports and describe the meaning of any additional nonoption arguments.

Some options are common to a number of programs. The most frequently used of these are the (or

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
67), (or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
69), and (or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
71) options that specify connection parameters. They indicate the host where the MySQL server is running, and the user name and password of your MySQL account. All MySQL client programs understand these options; they enable you to specify which server to connect to and the account to use on that server. Other connection options are (or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
73) to specify a TCP/IP port number and (or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
75) to specify a Unix socket file on Unix (or named pipe name on Windows). For more information on options that specify connection options, see .

You may find it necessary to invoke MySQL programs using the path name to the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
76 directory in which they are installed. This is likely to be the case if you get a “program not found” error whenever you attempt to run a MySQL program from any directory other than the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
76 directory. To make it more convenient to use MySQL, you can add the path name of the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
76 directory to your
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 environment variable setting. That enables you to run a program by typing only its name, not its entire path name. For example, if is installed in
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
80, you can run the program by invoking it as , and it is not necessary to invoke it as /usr/local/mysql/bin/mysql.

Consult the documentation for your command interpreter for instructions on setting your

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 variable. The syntax for setting environment variables is interpreter-specific. (Some information is given in .) After modifying your
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 setting, open a new console window on Windows or log in again on Unix so that the setting goes into effect.

4.2.2. Connecting to the MySQL Server

For a client program to be able to connect to the MySQL server, it must use the proper connection parameters, such as the name of the host where the server is running and the user name and password of your MySQL account. Each connection parameter has a default value, but you can override them as necessary using program options specified either on the command line or in an option file.

The examples here use the client program, but the principles apply to other clients such as , , or .

This command invokes without specifying any connection parameters explicitly:

shell> mysql

Because there are no parameter options, the default values apply:

  • The default host name is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52. On Unix, this has a special meaning, as described later.

  • The default user name is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    84 on Windows or your Unix login name on Unix.

  • No password is sent if neither

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 nor is given.

  • For , the first nonoption argument is taken as the name of the default database. If there is no such option, does not select a default database.

To specify the host name and user name explicitly, as well as a password, supply appropriate options on the command line:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb

For password options, the password value is optional:

  • If you use a

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 or option and specify the password value, there must be no space between
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 or and the password following it.

  • If you use a

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 or option but do not specify the password value, the client program prompts you to enter the password. The password is not displayed as you enter it. This is more secure than giving the password on the command line. Other users on your system may be able to see a password specified on the command line by executing a command such as ps auxw. See .

As just mentioned, including the password value on the command line can be a security risk. To avoid this problem, specify the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
70 or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
71 option without any following password value:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb

When the password option has no password value, the client program prints a prompt and waits for you to enter the password. (In these examples,

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
95 is not interpreted as a password because it is separated from the preceding password option by a space.)

On some systems, the library routine that MySQL uses to prompt for a password automatically limits the password to eight characters. That is a problem with the system library, not with MySQL. Internally, MySQL does not have any limit for the length of the password. To work around the problem, change your MySQL password to a value that is eight or fewer characters long, or put your password in an option file.

On Unix, MySQL programs treat the host name

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52 specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
73 option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
67 to specify a host name value of
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
02, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52, by using the option. For example:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP

The option enables you to establish a particular type of connection even when the other options would normally default to some other protocol.

If the server is configured to accept IPv6 connections, client can connect over IPv6 using . See .

On Windows, you can force a MySQL client to use a named-pipe connection by specifying the or option, or by specifying

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
09 (period) as the host name. If named-pipe connections are not enabled, an error occurs. Use the option to specify the name of the pipe if you do not want to use the default pipe name.

Connections to remote servers always use TCP/IP. This command connects to the server running on

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
11 using the default port number (3306):

shell> mysql --host=remote.example.com

To specify a port number explicitly, use the or

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
73 option:

shell> mysql --host=remote.example.com --port=13306

You can specify a port number for connections to a local server, too. However, as indicated previously, connections to

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52 on Unix will use a socket file by default. You will need to force a TCP/IP connection as already described or any option that specifies a port number will be ignored.

For this command, the program uses a socket file on Unix and the option is ignored:

shell> mysql --port=13306 --host=localhost

To cause the port number to be used, invoke the program in either of these ways:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP

The following list summarizes the options that can be used to control how client programs connect to the server:

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    The host where the server is running. The default value is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    20]

    The password of the MySQL account. As described earlier, the password value is optional, but if given, there must be no space between

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 or and the password following it. The default is to send no password.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. The server must be started with the option to enable named-pipe connections.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The port number to use for the connection, for connections made using TCP/IP. The default port number is 3306.

  • This option explicitly specifies a protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For example, connections on Unix to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52 are made using a Unix socket file by default:

    shell> mysql --host=localhost
    

    To force a TCP/IP connection to be used instead, specify a option:

    shell> mysql
    
    0

    The following table shows the permissible option values and indicates the platforms on which each value may be used. The values are not case sensitive.

    ValueConnection ProtocolPermissible Operating Systems

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    33TCP/IP connection to local or remote serverAll
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    34Unix socket file connection to local serverUnix only
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    35Named-pipe connection to local or remote serverWindows only
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    36Shared-memory connection to local serverWindows only

  • On Windows, the shared-memory name to use, for connections made using shared memory to a local server. The default value is

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    38. The shared-memory name is case sensitive.

    The server must be started with the option to enable shared-memory connections.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    41

    On Unix, the name of the Unix socket file to use, for connections made using a named pipe to a local server. The default Unix socket file name is

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    42.

    On Windows, the name of the named pipe to use, for connections to a local server. The default Windows pipe name is

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    43. The pipe name is not case sensitive.

    The server must be started with the option to enable named-pipe connections.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with are used for establishing a secure connection to the server using SSL, if the server is configured with SSL support. For details, see .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The user name of the MySQL account you want to use. The default user name is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    84 on Windows or your Unix login name on Unix.

It is possible to specify different default values to be used when you make a connection so that you need not enter them on the command line each time you invoke a client program. This can be done in a couple of ways:

  • You can specify connection parameters in the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    50 section of an option file. The relevant section of the file might look like this:

    shell> mysql
    
    1

    , discusses option files further.

  • You can specify some connection parameters using environment variables. The host can be specified for using

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    51. The MySQL user name can be specified using
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    52 (this is for Windows only). The password can be specified using
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    54, although this is insecure; see . For a list of variables, see .

4.2.3. Specifying Program Options

There are several ways to specify options for MySQL programs:

  • List the options on the command line following the program name. This is common for options that apply to a specific invocation of the program.

  • List the options in an option file that the program reads when it starts. This is common for options that you want the program to use each time it runs.

  • List the options in environment variables (see ). This method is useful for options that you want to apply each time the program runs. In practice, option files are used more commonly for this purpose, but , discusses one situation in which environment variables can be very helpful. It describes a handy technique that uses such variables to specify the TCP/IP port number and Unix socket file for the server and for client programs.

Options are processed in order, so if an option is specified multiple times, the last occurrence takes precedence. The following command causes to connect to the server running on

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
52:

shell> mysql
2

If conflicting or related options are given, later options take precedence over earlier options. The following command runs in “no column names” mode:

shell> mysql
3

MySQL programs determine which options are given first by examining environment variables, then by reading option files, and then by checking the command line. This means that environment variables have the lowest precedence and command-line options the highest.

You can take advantage of the way that MySQL programs process options by specifying default option values for a program in an option file. That enables you to avoid typing them each time you run the program while enabling you to override the defaults if necessary by using command-line options.

An option can be specified by writing it in full or as any unambiguous prefix. For example, the option can be given to as

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
56, but not as
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
57 because the latter is ambiguous:

shell> mysql
4

Be aware that the use of option prefixes can cause problems in the event that new options are implemented for a program. A prefix that is unambiguous now might become ambiguous in the future.

4.2.3.1. Using Options on the Command Line

Program options specified on the command line follow these rules:

  • Options are given after the command name.

  • An option argument begins with one dash or two dashes, depending on whether it is a short form or long form of the option name. Many options have both short and long forms. For example,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58 and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    50 are the short and long forms of the option that instructs a MySQL program to display its help message.

  • Option names are case sensitive.

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60 and
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61 are both legal and have different meanings. (They are the corresponding short forms of the
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    62 and
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    63 options.)

  • Some options take a value following the option name. For example,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    64 or indicate the MySQL server host to a client program. The option value tells the program the name of the host where the MySQL server is running.

  • For a long option that takes a value, separate the option name and the value by an “

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    66” sign. For a short option that takes a value, the option value can immediately follow the option letter, or there can be a space between:
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    67 and
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    64 are equivalent. An exception to this rule is the option for specifying your MySQL password. This option can be given in long form as or as . In the latter case (with no password value given), the program prompts you for the password. The password option also may be given in short form as
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    71 or as
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71. However, for the short form, if the password value is given, it must follow the option letter with no intervening space. The reason for this is that if a space follows the option letter, the program has no way to tell whether a following argument is supposed to be the password value or some other kind of argument. Consequently, the following two commands have two completely different meanings:

    shell> mysql
    
    5

    The first command instructs to use a password value of

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    65, but specifies no default database. The second instructs to prompt for the password value and to use
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    65 as the default database.

  • Within option names, dash (“

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    62”) and underscore (“
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    76”) may be used interchangeably. For example, and are equivalent. (However, the leading dashes cannot be given as underscores.)

  • For options that take a numeric value, the value can be given with a suffix of

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    79,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    80, or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    81 (either uppercase or lowercase) to indicate a multiplier of 1024, 10242 or 10243. For example, the following command tells to ping the server 1024 times, sleeping 10 seconds between each ping:

    shell> mysql
    
    6

Option values that contain spaces must be quoted when given on the command line. For example, the (or

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
83) option can be used with to pass SQL statements to the server. When this option is used, executes the statements in the option value and exits. The statements must be enclosed by quotation marks. For example, you can use the following command to obtain a list of user accounts:

shell> mysql
7

Note that the long form () is followed by an equals sign (

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
66).

If you wish to use quoted values within a statement, you will either need to escape the inner quotation marks, or use a different type of quotation marks within the statement from those used to quote the statement itself. The capabilities of your command processor dictate your choices for whether you can use single or double quotation marks and the syntax for escaping quote characters. For example, if your command processor supports quoting with single or double quotation marks, you can use double quotation marks around the statement, and single quotation marks for any quoted values within the statement.

Multiple SQL statements may be passed in the option value on the command line, separated by semicolons:

shell> mysql
8

4.2.3.2. Program Option Modifiers

Some options are “boolean” and control behavior that can be turned on or off. For example, the client supports a option that determines whether or not to display a row of column names at the beginning of query results. By default, this option is enabled. However, you may want to disable it in some instances, such as when sending the output of into another program that expects to see only data and not an initial header line.

To disable column names, you can specify the option using any of these forms:

shell> mysql
9

The

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
87 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
88 prefixes and the
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
89 suffix all have the same effect: They turn the option off.

The “enabled” form of the option may be specified in any of these ways:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
0

As of MySQL 5.6.2, the values

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
90,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
91,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
92, and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
93 are also recognized for boolean options (not case sensitive).

If an option is prefixed by

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
94, a program does not exit with an error if it does not recognize the option, but instead issues only a warning:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
1

The

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
94 prefix can be useful when you run programs from multiple installations of MySQL on the same machine and list options in an option file, An option that may not be recognized by all versions of a program can be given using the
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
94 prefix (or
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
97 in an option file). Versions of the program that recognize the option process it normally, and versions that do not recognize it issue a warning and ignore it.

enables a limit to be placed on how large client programs can set dynamic system variables. To do this, use a

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
98 prefix with the variable name. For example,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
99 prevents any client from making the query cache size larger than 4MB.

4.2.3.3. Using Option Files

Most MySQL programs can read startup options from option files (also sometimes called configuration files). Option files provide a convenient way to specify commonly used options so that they need not be entered on the command line each time you run a program. For the MySQL server, MySQL provides a number of .

To determine whether a program reads option files, invoke it with the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
50 option. (For , use and .) If the program reads option files, the help message indicates which files it looks for and which option groups it recognizes.

The

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file that contains login path options is created by the utility. See . A “login path” is an option group that permits only a limited set of options:
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
04,
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
05, and
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
06. Client programs specify which login path to read from
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 using the option.

On Windows, MySQL programs read startup options from the following files, in the specified order (top items are used first).

File NamePurpose

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
09\my.ini,
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
09\my.cnfGlobal options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
11,
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
12Global options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
13\my.ini,
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
13\my.cnfGlobal options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
15The file specified with , if any
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
17\.mylogin.cnfLogin path options

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
18 represents the location of your Windows directory. This is commonly
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
19. You can determine its exact location from the value of the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
18 environment variable using the following command:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
2

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
21 represents the MySQL installation directory. This is typically
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
22\MySQL\MySQL 5.6 Server where
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
23 represents the programs directory (usually
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
24 on English-language versions of Windows), when MySQL 5.6 has been installed using the installation and configuration wizards. See .

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
25 represents the value of the Windows application data directory. You can determine its exact location from the value of the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
25 environment variable using the following command:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
3

On Unix, Linux and Mac OS X, MySQL programs read startup options from the following files, in the specified order (top items are used first).

File NamePurpose

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
27Global options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
28Global options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
29/my.cnfGlobal options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
30Server-specific options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
15The file specified with , if any
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
33User-specific options
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
34Login path options

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
35 represents the current user's home directory (the value of
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
36).

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
37 represents the directory specified with the option to CMake when MySQL was built. By default, this is the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
39 directory located under the compiled-in installation directory.

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
40 is an environment variable containing the path to the directory in which the server-specific
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file resides. If
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
40 is not set and you start the server using the program, attempts to set
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
40 as follows:

  • Let

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    44 and
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    45 represent the path names of the MySQL base directory and data directory, respectively.

  • If there is a

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    41 file in
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    45 but not in
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    44, sets
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    40 to
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    45.

  • Otherwise, if

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    40 is not set and there is no
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    41 file in
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    45, sets
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    40 to
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    44.

In MySQL 5.6, use of

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
45 as the location for
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 is deprecated.

Typically,

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
45 is
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
59 for a binary installation or
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
60 for a source installation. Note that this is the data directory location that was specified at configuration time, not the one specified with the option when starts. Use of at runtime has no effect on where the server looks for option files, because it looks for them before processing any options.

MySQL looks for option files in the order just described and reads any that exist. If an option file that you want to use does not exist, create it with a plain text editor.

If multiple instances of a given option are found, the last instance takes precedence. There is one exception: For , the first instance of the option is used as a security precaution, to prevent a user specified in an option file from being overridden on the command line.

On Unix platforms, MySQL ignores configuration files that are world-writable. This is intentional as a security measure.

Any long option that may be given on the command line when running a MySQL program can be given in an option file as well. To get the list of available options for a program, run it with the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
50 option.

The syntax for specifying options in an option file is similar to command-line syntax (see ). However, in an option file, you omit the leading two dashes from the option name and you specify only one option per line. For example,

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
65 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
65 on the command line should be specified as
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
67 and
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
68 on separate lines in an option file. To specify an option of the form
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
69 in an option file, write it as
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
70.

Empty lines in option files are ignored. Nonempty lines can take any of the following forms:

  • shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    71,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    72

    Comment lines start with “

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    73” or “
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”. A “
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    73” comment can start in the middle of a line as well.

  • shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    76]

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    77 is the name of the program or group for which you want to set options. After a group line, any option-setting lines apply to the named group until the end of the option file or another group line is given. Option group names are not case sensitive.

  • shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    78

    This is equivalent to

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    79 on the command line.

  • shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    78=
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81

    This is equivalent to

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    79=
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81 on the command line. In an option file, you can have spaces around the “
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    66” character, something that is not true on the command line. You can optionally enclose the value within single quotation marks or double quotation marks, which is useful if the value contains a “
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    73” comment character.

Leading and trailing spaces are automatically deleted from option names and values.

You can use the escape sequences “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
86”, “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
87”, “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
88”, “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
89”, “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
90”, and “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
91” in option values to represent the backspace, tab, newline, carriage return, backslash, and space characters. The escaping rules in option files are:

  • If a backslash is followed by a valid escape sequence character, the sequence is converted to the character represented by the sequence. For example, “

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    91” is converted to a space.

  • If a backslash is not followed by a valid escape sequence character, it remains unchanged. For example, “

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    93” is retained as is.

The preceding rules mean that a literal backslash can be given as “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
90”, or as “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
95” if it is not followed by a valid escape sequence character.

The rules for escape sequences in option files differ slightly from the rules for escape sequences in string literals in SQL statements. In the latter context, if “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96” is not a value escape sequence character, “\
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96
” becomes “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96” rather than “\
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96
”. See .

The escaping rules for option file values are especially pertinent for Windows path names, which use “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
95” as a path name separator. A separator in a Windows path name must be written as “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
90” if it is followed by an escape sequence character. It can be written as “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
90” or “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
95” if it is not. Alternatively, “
shell> mysql --host=remote.example.com
04” may be used in Windows path names and will be treated as “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
95”. Suppose that you want to specify a base directory of
shell> mysql --host=remote.example.com
06 in an option file. This can be done several ways. Some examples:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
4

If an option group name is the same as a program name, options in the group apply specifically to that program. For example, the

shell> mysql --host=remote.example.com
07 and
shell> mysql --host=remote.example.com
08 groups apply to the server and the client program, respectively.

The

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 option group is read by all client programs (but not by ). This enables you to specify options that apply to all clients. For example,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 is the perfect group to use to specify the password that you use to connect to the server. (But make sure that the option file is readable and writable only by yourself, so that other people cannot find out your password.) Be sure not to put an option in the
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 group unless it is recognized by all client programs that you use. Programs that do not understand the option quit after displaying an error message if you try to run them.

Here is a typical global option file:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
5

The preceding option file uses

shell> mysql --host=remote.example.com
12=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81 syntax for the lines that set the and variables.

Here is a typical user option file:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
6

If you want to create option groups that should be read by servers from a specific MySQL release series only, you can do this by using groups with names of

shell> mysql --host=remote.example.com
16,
shell> mysql --host=remote.example.com
17, and so forth. The following group indicates that the
shell> mysql --host=remote.example.com
18 option should be used only by MySQL servers with 5.6.x version numbers:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
7

It is possible to use

shell> mysql --host=remote.example.com
19 directives in option files to include other option files and
shell> mysql --host=remote.example.com
20 to search specific directories for option files. For example, to include the
shell> mysql --host=remote.example.com
21 file, use the following directive:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
8

To search the

shell> mysql --host=remote.example.com
22 directory and read option files found there, use this directive:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
9

There is no guarantee about the order in which the option files in the directory will be read.

Currently, any files to be found and included using the

shell> mysql --host=remote.example.com
20 directive on Unix operating systems must have file names ending in
shell> mysql --host=remote.example.com
24. On Windows, this directive checks for files with the
shell> mysql --host=remote.example.com
25 or
shell> mysql --host=remote.example.com
24 extension.

Write the contents of an included option file like any other option file. That is, it should contain groups of options, each preceded by a

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
76] line that indicates the program to which the options apply.

While an included file is being processed, only those options in groups that the current program is looking for are used. Other groups are ignored. Suppose that a

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file contains this line:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
8

And suppose that

shell> mysql --host=remote.example.com
21 looks like this:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
1

If

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 is processed by , only the
shell> mysql --host=remote.example.com
07 group in
shell> mysql --host=remote.example.com
21 is used. If the file is processed by , only the
shell> mysql --host=remote.example.com
33 group is used. If the file is processed by any other program, no options in
shell> mysql --host=remote.example.com
21 are used.

The

shell> mysql --host=remote.example.com
20 directive is processed similarly except that all option files in the named directory are read.

4.2.3.4. Command-Line Options that Affect Option-File Handling

Most MySQL programs that support option files handle the following options. They affect option-file handling, so they must be given on the command line and not in an option file. To work properly, each of these options must immediately follow the command name, with these exceptions:

When specifying file names, you should avoid the use of the “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
35” shell metacharacter because it might not be interpreted as you expect.

  • Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, the program exits with an error.

    shell> mysql --host=remote.example.com
    
    38 is interpreted relative to the current directory if given as a relative path name rather than a full path name.

  • Use only the given option file. If the file does not exist or is otherwise inaccessible, the program exits with an error.

    shell> mysql --host=remote.example.com
    
    38 is interpreted relative to the current directory if given as a relative path name rather than a full path name.

  • If this option is given, the program reads not only its usual option groups, but also groups with the usual names and a suffix of

    shell> mysql --host=remote.example.com
    
    42. For example, the client normally reads the
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    50 and
    shell> mysql --host=remote.example.com
    
    08 groups. If the option is given, also reads the
    shell> mysql --host=remote.example.com
    
    46 and
    shell> mysql --host=remote.example.com
    
    47 groups.

  • Read options from the named login path in the

    shell> mysql --host=remote.example.com
    
    49 login file. A “login path” is an option group that permits only a limited set of options:
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    04,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    05, and
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06. Think of a login path as a set of values that indicate the server host and the credentials for authenticating with the server. To create the login file, use the utility. See . This option was added in MySQL 5.6.6.

  • Do not read any option files. If a program does not start because it is reading unknown options from an option file, can be used to prevent the program from reading them.

    The exception is that the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 file, if it exists, is read in all cases. This permits passwords to be specified in a safer way than on the command line even when is used. (
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 is created by the utility. See .)

  • Print the program name and all options that it gets from option files.

4.2.3.5. Using Options to Set Program Variables

Many MySQL programs have internal variables that can be set at runtime using the statement. See , and .

Most of these program variables also can be set at server startup by using the same syntax that applies to specifying program options. For example, has a

shell> mysql --host=remote.example.com
15 variable that controls the maximum size of its communication buffer. To set the
shell> mysql --host=remote.example.com
15 variable for to a value of 16MB, use either of the following commands:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
2

The first command specifies the value in bytes. The second specifies the value in megabytes. For variables that take a numeric value, the value can be given with a suffix of

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
79,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
80, or
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
81 (either uppercase or lowercase) to indicate a multiplier of 1024, 10242 or 10243. (For example, when used to set
shell> mysql --host=remote.example.com
15, the suffixes indicate units of kilobytes, megabytes, or gigabytes.)

In an option file, variable settings are given without the leading dashes:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
3

Or:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
4

If you like, underscores in a variable name can be specified as dashes. The following option groups are equivalent. Both set the size of the server's key buffer to 512MB:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
5

A variable can be specified by writing it in full or as any unambiguous prefix. For example, the

shell> mysql --host=remote.example.com
15 variable can be set for as
shell> mysql --host=remote.example.com
68, but not as
shell> mysql --host=remote.example.com
69 because the latter is ambiguous:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
6

Be aware that the use of variable prefixes can cause problems in the event that new variables are implemented for a program. A prefix that is unambiguous now might become ambiguous in the future.

Suffixes for specifying a value multiplier can be used when setting a variable at server startup, but not to set the value with at runtime. On the other hand, with you can assign a variable's value using an expression, which is not true when you set a variable at server startup. For example, the first of the following lines is legal at server startup, but the second is not:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
7

Conversely, the second of the following lines is legal at runtime, but the first is not:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
8

4.2.3.6. Option Defaults, Options Expecting Values, and the
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
66 Sign

By convention, long forms of options that assign a value are written with an equals (

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
66) sign, like this:

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
9

For options that require a value (that is, not having a default value), the equals sign is not required, and so the following is also valid:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
0

In both cases, the client attempts to connect to a MySQL server running on the host named “tonfisk” using an account with the user name “jon”.

Due to this behavior, problems can occasionally arise when no value is provided for an option that expects one. Consider the following example, where a user connects to a MySQL server running on host

shell> mysql --host=remote.example.com
74 as user
shell> mysql --host=remote.example.com
75:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
1

Omitting the required value for one of these option yields an error, such as the one shown here:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
2

In this case, was unable to find a value following the option because nothing came after it on the command line. However, if you omit the value for an option that is not the last option to be used, you obtain a different error that you may not be expecting:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
3

Because assumes that any string following on the command line is a host name, is interpreted as , and the client attempts to connect to a MySQL server running on a host named “--user”.

Options having default values always require an equals sign when assigning a value; failing to do so causes an error. For example, the MySQL server option has the default value

shell> mysql --host=remote.example.com
82.err, where
shell> mysql --host=remote.example.com
83 is the name of the host on which MySQL is running. Assume that you are running MySQL on a computer whose host name is “tonfisk”, and consider the following invocation of :

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
4

After shutting down the server, restart it as follows:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
5

The result is the same, since is not followed by anything else on the command line, and it supplies its own default value. (The

shell> mysql --host=remote.example.com
85 character tells the operating system to run MySQL in the background; it is ignored by MySQL itself.) Now suppose that you wish to log errors to a file named
shell> mysql --host=remote.example.com
86. You might try starting the server with
shell> mysql --host=remote.example.com
87, but this does not have the intended effect, as shown here:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
6

The server attempted to start using

shell> mysql --host=remote.example.com
88 as the error log, but then shut down. Examining the last few lines of this file shows the reason:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
7

Because the option supplies a default value, you must use an equals sign to assign a different value to it, as shown here:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
8

Now the server has been started successfully, and is logging errors to the file

shell> mysql --host=remote.example.com
90.

Similar issues can arise when specifying option values in option files. For example, consider a

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file that contains the following:

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
9

When the client reads this file, these entries are parsed as or , with the result shown here:

shell> mysql --host=remote.example.com
0

However, in option files, an equals sign is not assumed. Suppose the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file is as shown here:

shell> mysql --host=remote.example.com
1

Trying to start in this case causes a different error:

shell> mysql --host=remote.example.com
2

A similar error would occur if you were to write

shell> mysql --host=remote.example.com
96 in the option file rather than
shell> mysql --host=remote.example.com
97. Instead, you must use the equals sign:

shell> mysql --host=remote.example.com
3

Now the login attempt succeeds:

shell> mysql --host=remote.example.com
4

This is not the same behavior as with the command line, where the equals sign is not required:

shell> mysql --host=remote.example.com
5

In MySQL 5.6, specifying an option requiring a value without a value in an option file causes the server to abort with an error. Suppose that

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 contains the following:

shell> mysql --host=remote.example.com
6

This causes the server to fail on startup, as shown here:

shell> mysql --host=remote.example.com
7

The option does not require an argument; however, the option requires one, as shown in the error log (which in the absence of a specified value, defaults to

shell> mysql --host=remote.example.com --port=13306
01/
shell> mysql --host=remote.example.com --port=13306
02.err):

shell> mysql --host=remote.example.com
8

This is a change from previous behavior, where the server would have interpreted the last two lines in the example

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file as
shell> mysql --host=remote.example.com --port=13306
04 and created a relay log file using “relay_log_index” as the basename. (Bug #25192)

4.2.4. Setting Environment Variables

Environment variables can be set at the command prompt to affect the current invocation of your command processor, or set permanently to affect future invocations. To set a variable permanently, you can set it in a startup file or by using the interface provided by your system for this purpose. Consult the documentation for your command interpreter for specific details. , lists all environment variables that affect MySQL program operation.

To specify a value for an environment variable, use the syntax appropriate for your command processor. For example, on Windows, you can set the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
52 variable to specify your MySQL account name. To do so, use this syntax:

shell> mysql --host=remote.example.com
9

The syntax on Unix depends on your shell. Suppose that you want to specify the TCP/IP port number using the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
53 variable. Typical syntax (such as for sh, ksh, bash, zsh, and so on) is as follows:

shell> mysql --host=remote.example.com --port=13306
0

The first command sets the variable, and the

shell> mysql --host=remote.example.com --port=13306
07 command exports the variable to the shell environment so that its value becomes accessible to MySQL and other processes.

For csh and tcsh, use setenv to make the shell variable available to the environment:

shell> mysql --host=remote.example.com --port=13306
1

The commands to set environment variables can be executed at your command prompt to take effect immediately, but the settings persist only until you log out. To have the settings take effect each time you log in, use the interface provided by your system or place the appropriate command or commands in a startup file that your command interpreter reads each time it starts.

On Windows, you can set environment variables using the System Control Panel (under Advanced).

On Unix, typical shell startup files are

shell> mysql --host=remote.example.com --port=13306
08 or
shell> mysql --host=remote.example.com --port=13306
09 for bash, or
shell> mysql --host=remote.example.com --port=13306
10 for tcsh.

Suppose that your MySQL programs are installed in

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
80 and that you want to make it easy to invoke these programs. To do this, set the value of the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 environment variable to include that directory. For example, if your shell is bash, add the following line to your
shell> mysql --host=remote.example.com --port=13306
08 file:

shell> mysql --host=remote.example.com --port=13306
2

bash uses different startup files for login and nonlogin shells, so you might want to add the setting to

shell> mysql --host=remote.example.com --port=13306
08 for login shells and to
shell> mysql --host=remote.example.com --port=13306
09 for nonlogin shells to make sure that
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 is set regardless.

If your shell is tcsh, add the following line to your

shell> mysql --host=remote.example.com --port=13306
10 file:

shell> mysql --host=remote.example.com --port=13306
3

If the appropriate startup file does not exist in your home directory, create it with a text editor.

After modifying your

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
79 setting, open a new console window on Windows or log in again on Unix so that the setting goes into effect.

4.3. MySQL Server and Server-Startup Programs

This section describes , the MySQL server, and several programs that are used to start the server.

4.3.1. mysqld — The MySQL Server

, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.

When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.

The program has many options that can be specified at startup. For a complete list of options, run this command:

shell> mysql --host=remote.example.com --port=13306
4

MySQL Server also has a set of system variables that affect its operation as it runs. System variables can be set at server startup, and many of them can be changed at runtime to effect dynamic server reconfiguration. MySQL Server also has a set of status variables that provide information about its operation. You can monitor these status variables to access runtime performance characteristics.

For a full description of MySQL Server command options, system variables, and status variables, see . For information about installing MySQL and setting up the initial configuration, see Chapter 2, Installing and Upgrading MySQL.

4.3.2. mysqld_safe — MySQL Server Startup Script

is the recommended way to start a server on Unix. adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file. A description of error logging is given later in this section.

tries to start an executable named . To override the default behavior and specify explicitly the name of the server you want to run, specify a or option to . You can also use to indicate the directory where should look for the server.

Many of the options to are the same as the options to . See .

Options unknown to are passed to if they are specified on the command line, but ignored if they are specified in the

shell> mysql --host=remote.example.com --port=13306
22 group of an option file. See .

reads all options from the

shell> mysql --host=remote.example.com
07,
shell> mysql --host=remote.example.com --port=13306
24, and
shell> mysql --host=remote.example.com --port=13306
22 sections in option files. For example, if you specify a
shell> mysql --host=remote.example.com
07 section like this, will find and use the option:

shell> mysql --host=remote.example.com --port=13306
5

For backward compatibility, also reads

shell> mysql --host=remote.example.com --port=13306
28 sections, although you should rename such sections to
shell> mysql --host=remote.example.com --port=13306
22 in MySQL 5.6 installations.

supports the following options. It also reads option files and supports the options for processing them described at .

Table 4.1. 

shell> mysql --host=remote.example.com --port=13306
30 Options


  • Display a help message and exit.

  • The path to the MySQL installation directory.

  • The size of the core file that should be able to create. The option value is passed to ulimit -c.

  • The path to the data directory.

  • The name of an option file to be read in addition to the usual option files. This must be the first option on the command line if it is used. If the file does not exist or is otherwise inaccessible, the server will exit with an error.

  • The name of an option file to be read instead of the usual option files. This must be the first option on the command line if it is used.

  • If cannot find the server, use this option to indicate the path name to the directory where the server is located.

  • Write the error log to the given file. See .

  • The name of the library to use for memory allocation instead of the system

    shell> mysql --host=remote.example.com --port=13306
    
    40 library. Any library can be used by specifying its path name, but there is a shortcut form to enable use of the
    shell> mysql --host=remote.example.com --port=13306
    
    41 library that is shipped with binary MySQL distributions for Linux in MySQL 5.6.

    The option works by modifying the

    shell> mysql --host=remote.example.com --port=13306
    
    43 environment value to affect dynamic linking to enable the loader to find the memory-allocation library when runs:

    • If the option is not given, or is given without a value (),

      shell> mysql --host=remote.example.com --port=13306
      
      43 is not modified and no attempt is made to use
      shell> mysql --host=remote.example.com --port=13306
      
      41.

    • If the option is given as , looks for a

      shell> mysql --host=remote.example.com --port=13306
      
      41 library in
      shell> mysql --host=remote.example.com --port=13306
      
      49 and then in the MySQL
      shell> mysql --host=remote.example.com --port=13306
      
      50 location (for example,
      shell> mysql --host=remote.example.com --port=13306
      
      51 or whatever is appropriate). If
      shell> mysql --host=remote.example.com --port=13306
      
      52 is found, its path name is added to the beginning of the
      shell> mysql --host=remote.example.com --port=13306
      
      43 value for . If
      shell> mysql --host=remote.example.com --port=13306
      
      41 is not found, aborts with an error.

    • If the option is given as , that full path is added to the beginning of the

      shell> mysql --host=remote.example.com --port=13306
      
      43 value. If the full path points to a nonexistent or unreadable file, aborts with an error.

    • For cases where adds a path name to

      shell> mysql --host=remote.example.com --port=13306
      
      43, it adds the path to the beginning of any existing value the variable already has.

    Linux users can use the

    shell> mysql --host=remote.example.com --port=13306
    
    58 included in binary packages by adding these lines to the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    41 file:

    shell> mysql --host=remote.example.com --port=13306
    
    6

    Those lines also suffice for users on any platform who have installed a

    shell> mysql --host=remote.example.com --port=13306
    
    41 package in
    shell> mysql --host=remote.example.com --port=13306
    
    49. To use a specific
    shell> mysql --host=remote.example.com --port=13306
    
    41 library, specify its full path name. Example:

    shell> mysql --host=remote.example.com --port=13306
    
    7
  • The name of the server program (in the

    shell> mysql --host=remote.example.com --port=13306
    
    64 directory) that you want to start. This option is needed if you use the MySQL binary distribution but have the data directory outside of the binary distribution. If cannot find the server, use the option to indicate the path name to the directory where the server is located.

  • This option is similar to the option, but you specify only the suffix for the server program name. The basename is assumed to be . For example, if you use , starts the program in the

    shell> mysql --host=remote.example.com --port=13306
    
    64 directory. If the argument to is empty, uses in the
    shell> mysql --host=remote.example.com --port=13306
    
    64 directory.

  • Use the

    shell> mysql --host=remote.example.com --port=13306
    
    73 program to set the server's scheduling priority to the given value.

  • Do not read any option files. This must be the first option on the command line if it is used.

  • The number of files that should be able to open. The option value is passed to ulimit -n. Note that you need to start as

    shell> mysql --host=remote.example.com --port=13306
    
    76 for this to work properly!

  • The path name of the process ID file.

  • The port number that the server should use when listening for TCP/IP connections. The port number must be 1024 or higher unless the server is started by the

    shell> mysql --host=remote.example.com --port=13306
    
    76 system user.

  • Do not try to kill stray processes at startup. This option works only on Linux.

  • The Unix socket file that the server should use when listening for local connections.

  • ,

    causes error messages to be sent to

    shell> mysql --host=remote.example.com --port=13306
    
    85 on systems that support the logger program.
    shell> mysql --host=remote.example.com --port=13306
    
    83 suppresses the use of
    shell> mysql --host=remote.example.com --port=13306
    
    85; messages are written to an error log file.

    When

    shell> mysql --host=remote.example.com --port=13306
    
    85 is used, the
    shell> mysql --host=remote.example.com --port=13306
    
    89 syslog priority/facility is used for all log messages.

  • For logging to

    shell> mysql --host=remote.example.com --port=13306
    
    85, messages from and are written with a tag of
    shell> mysql --host=remote.example.com --port=13306
    
    30 and
    shell> mysql --host=remote.example.com --port=13306
    
    93, respectively. To specify a suffix for the tag, use , which modifies the tags to be
    shell> mysql --host=remote.example.com --port=13306
    
    95 and
    shell> mysql --host=remote.example.com --port=13306
    
    96.

  • Set the

    shell> mysql --host=remote.example.com --port=13306
    
    98 time zone environment variable to the given option value. Consult your operating system documentation for legal time zone specification formats.

  • Run the server as the user having the name

    shell> mysql --port=13306 --host=localhost
    
    01 or the numeric user ID
    shell> mysql --port=13306 --host=localhost
    
    00. (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)

If you execute with the or option to name an option file, the option must be the first one given on the command line or the option file will not be used. For example, this command will not use the named option file:

shell> mysql --host=remote.example.com --port=13306
8

Instead, use the following command:

shell> mysql --host=remote.example.com --port=13306
9

The script is written so that it normally can start a server that was installed from either a source or a binary distribution of MySQL, even though these types of distributions typically install the server in slightly different locations. (See .) expects one of the following conditions to be true:

  • The server and databases can be found relative to the working directory (the directory from which is invoked). For binary distributions, looks under its working directory for

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    76 and
    shell> mysql --port=13306 --host=localhost
    
    06 directories. For source distributions, it looks for
    shell> mysql --port=13306 --host=localhost
    
    07 and
    shell> mysql --port=13306 --host=localhost
    
    08 directories. This condition should be met if you execute from your MySQL installation directory (for example,
    shell> mysql --port=13306 --host=localhost
    
    09 for a binary distribution).

  • If the server and databases cannot be found relative to the working directory, attempts to locate them by absolute path names. Typical locations are

    shell> mysql --port=13306 --host=localhost
    
    10 and
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    60. The actual locations are determined from the values configured into the distribution at the time it was built. They should be correct if MySQL is installed in the location specified at configuration time.

Because tries to find the server and databases relative to its own working directory, you can install a binary distribution of MySQL anywhere, as long as you run from the MySQL installation directory:

shell> mysql --port=13306 --host=localhost
0

If fails, even when invoked from the MySQL installation directory, you can specify the and options to indicate the directories in which the server and databases are located on your system.

In MySQL 5.6.5 and later, tries to use the sleep and date system utilities to determine how many times it has attempted to start this second, and—if these are present and this is greater than 5 times—is forced to wait 1 full second before starting again. This is intended to prevent excessive CPU usage in the event of repeated failures. (Bug #11761530, Bug #54035)

When you use to start , arranges for error (and notice) messages from itself and from to go to the same destination.

There are several options for controlling the destination of these messages:

  • : Write error messages to

    shell> mysql --host=remote.example.com --port=13306
    
    85 on systems that support the logger program.

  • : Do not write error messages to

    shell> mysql --host=remote.example.com --port=13306
    
    85. Messages are written to the default error log file (
    shell> mysql --host=remote.example.com
    
    82.err in the data directory), or to a named file if the option is given.

  • : Write error messages to the named error file.

If none of these options is given, the default is .

If and are both given, a warning is issued and takes precedence.

When writes a message, notices go to the logging destination (

shell> mysql --host=remote.example.com --port=13306
85 or the error log file) and
shell> mysql --port=13306 --host=localhost
26. Errors go to the logging destination and
shell> mysql --port=13306 --host=localhost
27.

Normally, you should not edit the script. Instead, configure by using command-line options or options in the

shell> mysql --host=remote.example.com --port=13306
22 section of a
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 option file. In rare cases, it might be necessary to edit to get it to start the server properly. However, if you do this, your modified version of might be overwritten if you upgrade MySQL in the future, so you should make a copy of your edited version that you can reinstall.

4.3.3. mysql.server — MySQL Server Startup Script

MySQL distributions on Unix include a script named . It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the Mac OS X Startup Item for MySQL.

can be found in the

shell> mysql --port=13306 --host=localhost
30 directory under your MySQL installation directory or in a MySQL source distribution.

If you use the Linux server RPM package (

shell> mysql --port=13306 --host=localhost
31.rpm), the script will be installed in the
shell> mysql --port=13306 --host=localhost
32 directory with the name
shell> mysql --port=13306 --host=localhost
33. You need not install it manually. See , for more information on the Linux RPM packages.

Some vendors provide RPM packages that install a startup script under a different name such as .

If you install MySQL from a source distribution or using a binary distribution format that does not install automatically, you can install it manually. Instructions are provided in .

reads options from the

shell> mysql --port=13306 --host=localhost
34 and
shell> mysql --host=remote.example.com
07 sections of option files. For backward compatibility, it also reads
shell> mysql --port=13306 --host=localhost
36 sections, although you should rename such sections to
shell> mysql --port=13306 --host=localhost
34 when using MySQL 5.6.

supports the following options.

4.3.4. mysqld_multi — Manage Multiple MySQL Servers

is designed to manage several processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status.

searches for groups named

shell> mysql --port=13306 --host=localhost
38] in
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 (or in the file named by the option).
shell> mysql --port=13306 --host=localhost
41 can be any positive integer. This number is referred to in the following discussion as the option group number, or
shell> mysql --port=13306 --host=localhost
42. Group numbers distinguish option groups from one another and are used as arguments to to specify which servers you want to start, stop, or obtain a status report for. Options listed in these groups are the same that you would use in the
shell> mysql --host=remote.example.com
07 group used for starting . (See, for example, .) However, when using multiple servers, it is necessary that each one use its own value for options such as the Unix socket file and TCP/IP port number. For more information on which options must be unique per server in a multiple-server environment, see .

To invoke , use the following syntax:

shell> mysql --port=13306 --host=localhost
1

shell> mysql --port=13306 --host=localhost
44,
shell> mysql --port=13306 --host=localhost
45,
shell> mysql --port=13306 --host=localhost
46 (stop and restart), and
shell> mysql --port=13306 --host=localhost
47 indicate which operation to perform. (
shell> mysql --port=13306 --host=localhost
46 is available as of MySQL 5.6.3.) You can perform the designated operation for a single server or multiple servers, depending on the
shell> mysql --port=13306 --host=localhost
42 list that follows the option name. If there is no list, performs the operation for all servers in the option file.

Each

shell> mysql --port=13306 --host=localhost
42 value represents an option group number or range of group numbers. The value should be the number at the end of the group name in the option file. For example, the
shell> mysql --port=13306 --host=localhost
42 for a group named
shell> mysql --port=13306 --host=localhost
52 is
shell> mysql --port=13306 --host=localhost
53. To specify a range of numbers, separate the first and last numbers by a dash. The
shell> mysql --port=13306 --host=localhost
42 value
shell> mysql --port=13306 --host=localhost
55 represents groups
shell> mysql --port=13306 --host=localhost
56 through
shell> mysql --port=13306 --host=localhost
57. Multiple groups or group ranges can be specified on the command line, separated by commas. There must be no whitespace characters (spaces or tabs) in the
shell> mysql --port=13306 --host=localhost
42 list; anything after a whitespace character is ignored.

This command starts a single server using option group

shell> mysql --port=13306 --host=localhost
52:

shell> mysql --port=13306 --host=localhost
2

This command stops several servers, using option groups

shell> mysql --port=13306 --host=localhost
60 and
shell> mysql --port=13306 --host=localhost
56 through
shell> mysql --port=13306 --host=localhost
57:

shell> mysql --port=13306 --host=localhost
3

For an example of how you might set up an option file, use this command:

shell> mysql --port=13306 --host=localhost
4

searches for option files as follows:

  • With , no option files are read.

  • With , only the named file is read.

  • Otherwise, option files in the standard list of locations are read, including any file named by the option, if one is given. (If the option is given multiple times, the last value is used.)

Option files read are searched for

shell> mysql --port=13306 --host=localhost
66 and
shell> mysql --port=13306 --host=localhost
38] option groups. The
shell> mysql --port=13306 --host=localhost
66 group can be used for options to itself.
shell> mysql --port=13306 --host=localhost
38] groups can be used for options passed to specific instances.

The

shell> mysql --host=remote.example.com
07 or
shell> mysql --host=remote.example.com --port=13306
22 groups can be used for common options read by all instances of or . You can specify a option to use a different configuration file for that instance, in which case the
shell> mysql --host=remote.example.com
07 or
shell> mysql --host=remote.example.com --port=13306
22 groups from that file will be used for that instance.

supports the following options.

  • Display a help message and exit.

  • Display a sample option file.

  • Specify the name of the log file. If the file exists, log output is appended to it.

  • The binary to be used to stop servers.

  • The binary to be used. Note that you can specify as the value for this option also. If you use to start the server, you can include the

    shell> mysql --host=remote.example.com --port=13306
    
    93 or
    shell> mysql --host=remote.example.com --port=13306
    
    64 options in the corresponding
    shell> mysql --port=13306 --host=localhost
    
    38] option group. These options indicate the name of the server that should start and the path name of the directory where the server is located. (See the descriptions for these options in .) Example:

    shell> mysql --port=13306 --host=localhost
    
    5
  • Print log information to

    shell> mysql --port=13306 --host=localhost
    
    26 rather than to the log file. By default, output goes to the log file.

  • The password of the MySQL account to use when invoking . Note that the password value is not optional for this option, unlike for other MySQL programs.

  • Silent mode; disable warnings.

  • Connect to each MySQL server through the TCP/IP port instead of the Unix socket file. (If a socket file is missing, the server might still be running, but accessible only through the TCP/IP port.) By default, connections are made using the Unix socket file. This option affects

    shell> mysql --port=13306 --host=localhost
    
    45 and
    shell> mysql --port=13306 --host=localhost
    
    47 operations.

  • The user name of the MySQL account to use when invoking .

  • Be more verbose.

  • Display version information and exit.

Some notes about :

  • Most important: Before using be sure that you understand the meanings of the options that are passed to the servers and why you would want to have separate processes. Beware of the dangers of using multiple servers with the same data directory. Use separate data directories, unless you know what you are doing. Starting multiple servers with the same data directory does not give you extra performance in a threaded system. See .

  • Make sure that the data directory for each server is fully accessible to the Unix account that the specific process is started as. Do not use the Unix

    shell> mysql --host=remote.example.com --port=13306
    
    76 account for this, unless you know what you are doing. See .

  • Make sure that the MySQL account used for stopping the servers (with the program) has the same user name and password for each server. Also, make sure that the account has the privilege. If the servers that you want to manage have different user names or passwords for the administrative accounts, you might want to create an account on each server that has the same user name and password. For example, you might set up a common

    shell> mysql --port=13306 --host=localhost
    
    95 account by executing the following commands for each server:

    shell> mysql --port=13306 --host=localhost
    
    6

    See . You have to do this for each server. Change the connection parameters appropriately when connecting to each one. Note that the host name part of the account name must permit you to connect as

    shell> mysql --port=13306 --host=localhost
    
    95 from the host where you want to run .

  • The Unix socket file and the TCP/IP port number must be different for every . (Alternatively, if the host has multiple network addresses, you can use to cause different servers to listen to different interfaces.)

  • The option is very important if you are using to start (for example, ) Every should have its own process ID file. The advantage of using instead of is that monitors its process and restarts it if the process terminates due to a signal sent using

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    00 or for other reasons, such as a segmentation fault. Please note that the script might require that you start it from a certain place. This means that you might have to change location to a certain directory before running . If you have problems starting, please see the script. Check especially the lines:

    shell> mysql --port=13306 --host=localhost
    
    7

    The test performed by these lines should be successful, or you might encounter problems. See .

  • You might want to use the option for , but to do this you need to run the script as the Unix superuser (

    shell> mysql --host=remote.example.com --port=13306
    
    76). Having the option in the option file doesn't matter; you just get a warning if you are not the superuser and the processes are started under your own Unix account.

The following example shows how you might set up an option file for use with . The order in which the programs are started or stopped depends on the order in which they appear in the option file. Group numbers need not form an unbroken sequence. The first and fifth

shell> mysql --port=13306 --host=localhost
38] groups were intentionally omitted from the example to illustrate that you can have “gaps” in the option file. This gives you more flexibility.

shell> mysql --port=13306 --host=localhost
8

See .

The programs in this section are used when installing or upgrading MySQL.

4.4.1. comp_err — Compile MySQL Error Message File

creates the

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
04 file that is used by to determine the error messages to display for different error codes. normally is run automatically when MySQL is built. It compiles the
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
04 file from the plaintext file located at
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
06 in MySQL source distributions.

also generates

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
07,
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
08, and
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
09 header files.

For more information about how error messages are defined, see the MySQL Internals Manual.

Invoke like this:

shell> mysql --port=13306 --host=localhost
9

supports the following options.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    13

    The character set directory. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    14.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    16

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:O,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    19.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    21

    Print some debugging information when the program exits.

  • , -H

    shell> mysql --host=remote.example.com
    
    38

    The name of the error header file. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    07.

  • , -F

    shell> mysql --host=remote.example.com
    
    38

    The name of the input file. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    27.

  • , -N

    shell> mysql --host=remote.example.com
    
    38

    The name of the error name file. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    08.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    32

    The name of the output base directory. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    33.

  • , -O

    shell> mysql --host=remote.example.com
    
    38

    The name of the output file. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    04.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    41

    The name for the SQLSTATE header file. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    09.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

4.4.2. mysqlbug — Generate Bug Report

This program is obsolete.

The normal way to report bugs is to visit http://bugs.mysql.com/, which is the address for our bugs database. This database is public and can be browsed and searched by anyone. If you log in to the system, you can enter new reports.

4.4.3. mysql_install_db — Initialize MySQL Data Directory

initializes the MySQL data directory and creates the system tables that it contains, if they do not exist. It also initializes the and related data structures needed to manage tables. As of MySQL 5.6.8, is a Perl script and can be used on any system with Perl installed. Before 5.6.8, it is a shell script and is available only on Unix platforms.

As of MySQL 5.6.8, on Unix platforms, creates a default option file named

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 in the base installation directory. This file is created from a template included in the distribution package named
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
44. You can find the template in or under the base installation directory. When started using , the server uses
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 file by default. If
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 already exists, assumes it to be in use and writes a new file named
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
47 instead.

With one exception, the settings in the default option file are commented and have no effect. The exception is that the file changes the system variable from its default of to also include . This setting produces a server configuration that results in errors rather than warnings for bad data in operations that modify transactional tables. See .

To invoke , use the following syntax:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
0

Because the MySQL server, , needs to access the data directory when it runs later, you should either run from the same system account that will be used for running or run it as

shell> mysql --host=remote.example.com --port=13306
76 and use the option to indicate the user name that will run as. It might be necessary to specify other options such as or if does not use the correct locations for the installation directory or data directory. For example:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
1

needs to invoke with the and options.

If you have set a custom

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56 environment variable when performing the installation, and the specified directory is not accessible, may fail. If so, unset
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56 or set
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56 to point to the system temporary directory (usually
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
60).

After sets up the

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 , changes to some of tablespace characteristics require setting up a whole new . This includes the file name of the first file in the system tablespace and the number of undo logs. If you do not want to use the default values, make sure that the settings for the and configuration options are in place in the MySQL before running .

supports the following options, which can be specified on the command line or in the

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
64 group of an option file. (Options that are common to can also be specified in the
shell> mysql --host=remote.example.com
07 group.) Other options are passed to . For information about option files, see . also supports the options for processing option files described at .

  • The path to the MySQL installation directory.

  • ,

    The path to the MySQL data directory. Beginning with MySQL 5.6.8, is more strict about the option value. Only the last component of the path name is created if it does not exist; the parent directory must already exist or an error occurs.

  • Cause to run even if DNS does not work. Grant table entries that normally use host names will use IP addresses.

  • On Unix platforms, this option provides for more secure MySQL installation. Invoking with causes it to perform the following actions in addition to its normal operation:

    • Create a random password, assign it to the initial MySQL

      shell> mysql --host=remote.example.com --port=13306
      
      76 accounts, and set the “password expired” flag for those accounts.

    • Write the initial password file to the

      shell> mysql --port=13306 --host=127.0.0.1
      shell> mysql --port=13306 --protocol=TCP
      
      73 file in the directory named by the
      shell> mysql --port=13306 --host=127.0.0.1
      shell> mysql --port=13306 --protocol=TCP
      
      74 environment variable. Depending on operating system, using a command such as sudo may cause the value of
      shell> mysql --port=13306 --host=127.0.0.1
      shell> mysql --port=13306 --protocol=TCP
      
      74 to refer to the home directory of the
      shell> mysql --host=remote.example.com --port=13306
      
      76 system user.

      If

      shell> mysql --port=13306 --host=127.0.0.1
      shell> mysql --port=13306 --protocol=TCP
      
      73 already exists, the new password information is appended to it. Each password entry includes a timestamp so that in the event of multiple install operations it is possible to determine the password associated with each one.

      shell> mysql --port=13306 --host=127.0.0.1
      shell> mysql --port=13306 --protocol=TCP
      
      73 is created with mode 600 to be accessible only to the system user for whom it is created.

    • Remove the anonymous-user MySQL accounts.

    As a result of these actions, it is necessary after installation to start the server, connect as

    shell> mysql --host=remote.example.com --port=13306
    
    76 using the password written to the
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    73 file, and to assign a new
    shell> mysql --host=remote.example.com --port=13306
    
    76 password. Until this is done,
    shell> mysql --host=remote.example.com --port=13306
    
    76 cannot do anything else. This must be done for each
    shell> mysql --host=remote.example.com --port=13306
    
    76 account you intend to use. To change the password, you can use the statement (for example, with the client). You can also use or .

    New RPM install operations (not upgrades) invoke with the

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    70 option. (Install operations using RPMs for Unbreakable Linux Network are unaffected because they do not use .)

    As of MySQL 5.6.9, new Solaris PKG install operations (not upgrades) invoke with the

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    70 option.

    For install operations using a binary

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    87 distribution or a source distribution, you can invoke with the
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    70 option manually to make your MySQL installation more secure. This is recommended, particularly for sites with sensitive data.

    This option was added in MySQL 5.6.8.

  • For internal use. This option is used during the MySQL installation process for install operations performed using RPM packages.

  • Use IP addresses rather than host names when creating grant table entries. This option can be useful if your DNS does not work.

  • For internal use. This option specifies the directory under which looks for support files such as the error message file and the file for populating the help tables.

  • The system (login) user name to use for running . Files and directories created by will be owned by this user. You must be

    shell> mysql --host=remote.example.com --port=13306
    
    76 to use this option. By default, runs using your current login name and files and directories that it creates will be owned by you.

  • Verbose mode. Print more information about what the program does.

  • For internal use. This option is used for creating Windows distributions.

4.4.4. mysql_plugin — Configure MySQL Server Plugins

The utility enables MySQL administrators to manage which plugins a MySQL server loads. It provides an alternative to manually specifying the option at server startup or using the and statements at runtime. is available as of MySQL 5.6.3.

Depending on whether is invoked to enable or disable plugins, it inserts or deletes rows in the

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
99 table that serves as a plugin registry. (To perform this operation, invokes the MySQL server in bootstrap mode. This means that the server must not already be running.) For normal server startups, the server loads and enables plugins listed in
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
99 automatically. For additional control over plugin activation, use
shell> mysql --host=localhost
01 options named for specific plugins, as described in .

Each invocation of reads a configuration file to determine how to configure the plugins contained in a single plugin library object file. To invoke , use this syntax:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
2

shell> mysql --host=localhost
02 is the name of the plugin to configure.
shell> mysql --host=localhost
03 or
shell> mysql --host=localhost
04 (not case sensitive) specify whether to enable or disable components of the plugin library named in the configuration file. The order of the
shell> mysql --host=localhost
02 and
shell> mysql --host=localhost
03 or
shell> mysql --host=localhost
04 arguments does not matter.

For example, to configure components of a plugin library file named

shell> mysql --host=localhost
08 on Linux or
shell> mysql --host=localhost
09 on Windows, specify a
shell> mysql --host=localhost
02 value of
shell> mysql --host=localhost
11. Suppose that this plugin library contains three plugins,
shell> mysql --host=localhost
12,
shell> mysql --host=localhost
13, and
shell> mysql --host=localhost
14, all of which should be configured under control. By convention, configuration files have a suffix of
shell> mysql --host=remote.example.com
25 and the same basename as the plugin library, so the default configuration file name for this plugin library is
shell> mysql --host=localhost
16. The configuration file contents look like this:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
3

The first line in the

shell> mysql --host=localhost
16 file is the name of the library object file, without any extension such as
shell> mysql --host=localhost
18 or
shell> mysql --host=localhost
19. The remaining lines are the names of the components to be enabled or disabled. Each value in the file should be on a separate line. Lines on which the first character is
shell> mysql --host=localhost
20 are taken as comments and ignored.

To enable the plugins listed in the configuration file, invoke this way:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
4

To disable the plugins, use

shell> mysql --host=localhost
04 rather than
shell> mysql --host=localhost
03.

An error occurs if cannot find the configuration file or plugin library file, or if cannot start the MySQL server.

supports the following options, which can be specified on the command line or in the

shell> mysql --host=remote.example.com
07 group of any option file. For options specified in a
shell> mysql --host=remote.example.com
07 group, recognizes the , , and options and ignores others. For information about option files, see .

Table 4.2. 

shell> mysql --host=localhost
28 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql --host=localhost
    
    32

    The server base directory.

  • ,

    shell> mysql --host=localhost
    
    34

    The server data directory.

  • ,

    shell> mysql --host=localhost
    
    32

    The path to the program.

  • ,

    shell> mysql --host=localhost
    
    32

    The path to the server.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71

    Do not read values from the configuration file. This option enables an administrator to skip reading defaults from the configuration file.

    With , this option need not be given first on the command line, unlike most other MySQL programs that support .

  • ,

    shell> mysql --host=localhost
    
    43

    The server plugin directory.

  • , -i

    shell> mysql --host=remote.example.com
    
    38

    The configuration file. Relative path names are interpreted relative to the current directory. If this option is not given, the default is

    shell> mysql --host=localhost
    
    02.ini in the plugin directory, where
    shell> mysql --host=localhost
    
    02 is the
    shell> mysql --host=localhost
    
    02 argument on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    73

    Display the default values from the configuration file. This option causes to print the defaults for , , and if they are found in the configuration file. If no value for a variable is found, nothing is shown.

    With , this option need not be given first on the command line, unlike most other MySQL programs that support .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does. This option can be used multiple times to increase the amount of information.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

4.4.5. mysql_secure_installation — Improve MySQL Installation Security

This program enables you to improve the security of your MySQL installation in the following ways:

  • You can set a password for

    shell> mysql --host=remote.example.com --port=13306
    
    76 accounts.

  • You can remove

    shell> mysql --host=remote.example.com --port=13306
    
    76 accounts that are accessible from outside the local host.

  • You can remove anonymous-user accounts.

  • You can remove the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    65 database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with
    shell> mysql --host=localhost
    
    62.

helps you implement security recommendations similar to those described at .

Invoke without arguments:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
5

The script will prompt you to determine which actions to perform.

is not available on Windows.

4.4.6. mysql_tzinfo_to_sql — Load the Time Zone Tables

The program loads the time zone tables in the

shell> mysql --port=13306 --host=localhost
33 database. It is used on systems that have a zoneinfo database (the set of files describing time zones). Examples of such systems are Linux, FreeBSD, Solaris, and Mac OS X. One likely location for these files is the
shell> mysql --host=localhost
64 directory (
shell> mysql --host=localhost
65 on Solaris). If your system does not have a zoneinfo database, you can use the downloadable package described in .

can be invoked several ways:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
6

For the first invocation syntax, pass the zoneinfo directory path name to and send the output into the program. For example:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
7

reads your system's time zone files and generates SQL statements from them. processes those statements to load the time zone tables.

The second syntax causes to load a single time zone file

shell> mysql --host=localhost
66 that corresponds to a time zone name
shell> mysql --host=localhost
67:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
8

If your time zone needs to account for leap seconds, invoke using the third syntax, which initializes the leap second information.

shell> mysql --host=localhost
66 is the name of your time zone file:

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
9

After running , it is best to restart the server so that it does not continue to use any previously cached time zone data.

4.4.7. mysql_upgrade — Check and Upgrade MySQL Tables

examines all tables in all databases for incompatibilities with the current version of MySQL Server. also upgrades the system tables so that you can take advantage of new privileges or capabilities that might have been added.

should be executed each time you upgrade MySQL.

If finds that a table has a possible incompatibility, it performs a table check and, if problems are found, attempts a table repair. If the table cannot be repaired, see for manual table repair strategies.

On Windows Server 2008, Vista, and newer, you must run with administrator privileges. You can do this by running a Command Prompt as Administrator and running the command. Failure to do so may result in the upgrade failing to execute correctly.

You should always back up your current MySQL installation before performing an upgrade. See .

Some upgrade incompatibilities may require special handling before you upgrade your MySQL installation and run . See , for instructions on determining whether any such incompatibilities apply to your installation and how to handle them.

To use , make sure that the server is running, and then invoke it like this:

shell> mysql --host=localhost
0

After running , stop the server and restart it so that any changes made to the system tables take effect.

executes the following commands to check and repair tables and to upgrade the system tables:

shell> mysql --host=localhost
1

Notes about the preceding commands:

  • Because invokes with the option, it processes all tables in all databases, which might take a long time to complete. Each table is locked and therefore unavailable to other sessions while it is being processed. Check and repair operations can be time-consuming, particularly for large tables.

  • For details about what checks the option entails, see the description of the

    shell> mysql --host=localhost
    
    71 option of the statement (see ).

  • shell> mysql --host=localhost
    
    74 represents a script generated internally by that contains SQL statements to upgrade the tables in the
    shell> mysql --port=13306 --host=localhost
    
    33 database.

All checked and repaired tables are marked with the current MySQL version number. This ensures that next time you run with the same version of the server, it can tell whether there is any need to check or repair the table again.

also saves the MySQL version number in a file named

shell> mysql --host=localhost
76 in the data directory. This is used to quickly check whether all tables have been checked for this release so that table-checking can be skipped. To ignore this file and perform the check regardless, use the option.

If you install MySQL from RPM packages on Linux, you must install the server and client RPMs. is included in the server RPM but requires the client RPM because the latter includes . (See .)

does not upgrade the contents of the help tables. For upgrade instructions, see .

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost
78 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. Other options are passed to . For example, it might be necessary to specify the option. also supports the options for processing option files described at .

  • Display a short help message and exit.

  • The path to the MySQL installation directory. This option is accepted for backward compatibility but ignored.

  • The path to the data directory. This option is accepted for backward compatibility but ignored.

  • Print some debugging information when the program exits.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    21

    Print debugging information and memory and CPU usage statistics when the program exits.

  • The client-side authentication plugin to use. See .

    This option was added in MySQL 5.6.2.

  • Ignore the

    shell> mysql --host=localhost
    
    76 file and force execution of even if has already been executed for the current version of MySQL.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql --host=localhost
    
    93

    The path name of the directory to use for creating temporary files.

  • ,

    shell> mysql --host=localhost
    
    95

    Upgrade only the system tables, do not upgrade data.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server. The default user name is

    shell> mysql --host=remote.example.com --port=13306
    
    76.

  • Verbose mode. Print more information about what the program does.

  • Cause binary logging to be enabled while runs. In MySQL 5.6.6 and earlier, this was the default behavior. (To disable binary logging during the upgrade, it was necessary to use the inverse of this option, by starting the program with

    shell> mysql
    
    001.) Beginning with MySQL 5.6.7, binary logging by is disabled by default (Bug #14221043), and you must invoke the program explicitly with
    shell> mysql
    
    000 if you want its actions to be written to the binary log. (Also beginning with MySQL 5.6.7, the
    shell> mysql
    
    001 option effectively does nothing.)

    Running is not recommended with a MySQL Server that is running with global transaction identifiers enabled (Bug #13833710). This is because enabling GTIDs means that any updates which might need to perform on system tables using a nontransactional storage engine such as to fail. See , for more information.

4.5. MySQL Client Programs

This section describes client programs that connect to the MySQL server.

4.5.1. mysql — The MySQL Command-Line Tool

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 option. This forces 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 C API function in the client/server library rather than .

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

shell> mysql --host=localhost
2

Or:

shell> mysql --host=localhost
3

Then type an SQL statement, end it with “

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
74”,
shell> mysql
009, or
shell> mysql
010 and press Enter.

Typing Control+C causes to attempt to kill the current statement. If this cannot be done, or Control+C is typed again before the statement is killed, exits. Previously, Control+C caused to exit in all cases.

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

shell> mysql --host=localhost
4

On Unix, the client writes a record of executed statements to a history file. See .

supports the following options, which can be specified on the command line or in the

shell> mysql --host=remote.example.com
08 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • Enable automatic rehashing. This option is on by default, which enables database, table, and column name completion. Use to disable rehashing. That causes to start faster, but you must issue the

    shell> mysql
    
    017 command if you want to use name completion.

    To complete a name, enter the first part and press Tab. If the name is unambiguous, 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.

  • 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

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74 or
    shell> mysql
    
    010.)

  • ,

    shell> mysql
    
    022

    Print results using tab as the column separator, with each row on a new line. With this option, 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 option.

  • This option helps when processing output that may contain values. By default, translates

    shell> mysql
    
    026 in statement strings to
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    88 and interprets
    shell> mysql
    
    028 as the statement terminator. disables both features. It also disables all commands except
    shell> mysql
    
    030 and
    shell> mysql
    
    031 in non-interactive mode (for input piped to or loaded using the
    shell> mysql
    
    032 command).

    This option was added in MySQL 5.6.3.

  • On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

    This option is supported beginning with MySQL 5.6.1.

  • The directory where character sets are installed. See .

  • Write column names in results.

  • ,

    shell> mysql
    
    037

    Display result set metadata.

  • ,

    shell> mysql
    
    039

    Whether to preserve comments in statements sent to the server. The default is --skip-comments (discard comments), enable with --comments (preserve comments).

  • ,

    shell> mysql
    
    041

    Compress all information sent between the client and the server if both support compression.

  • ,

    shell> mysql
    
    043

    The database to use. This is useful primarily in an option file.

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql
    
    048.

  • Print some debugging information when the program exits.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    21

    Print debugging information and memory and CPU usage statistics when the program exits.

  • The client-side authentication plugin to use. See .

  • Use

    shell> mysql
    
    054 as the default character set for the client and connection.

    A common issue that can occur when the operating system uses

    shell> mysql
    
    055 or another multi-byte character set is that output from the client is formatted incorrectly, due to the fact that the MySQL client uses the
    shell> mysql
    
    056 character set by default. You can usually fix such issues by using this option to force the client to use the system character set instead.

    See , for more information.

  • Set the statement delimiter. The default is the semicolon character (“

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”).

  • Disable named commands. Use the

    shell> mysql
    
    060 form only, or use named commands only at the beginning of a line ending with a semicolon (“
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”). starts with this option enabled by default. However, even with this option, long-format commands still work from the first line. See .

  • Enable the

    shell> mysql
    
    063 cleartext authentication plugin. (See .) This option was added in MySQL 5.6.7.

  • ,

    shell> mysql
    
    065

    Execute the statement and quit. The default output format is like that produced with . See , for some examples. With this option, does not use the history file.

  • ,

    shell> mysql
    
    068

    Continue even if an SQL error occurs.

  • A colon-separated list of one or more patterns specifying statements not to log to the history file. For more information, see . This option was added in MySQL 5.6.8.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Connect to the MySQL server on the given host.

  • ,

    shell> mysql
    
    073

    Produce HTML output.

  • ,

    shell> mysql
    
    075

    Ignore spaces after function names. The effect of this is described in the discussion for the SQL mode (see ).

  • SQL statement to execute after connecting to the server. If auto-reconnect is enabled, the statement is executed again after reconnection occurs.

  • Write line numbers for errors. Disable this with .

  • Enable or disable

    shell> mysql
    
    081 capability for . With no value, the option enables
    shell> mysql
    
    081. The option may be given as or to explicitly disable or enable
    shell> mysql
    
    081. Enabling
    shell> mysql
    
    081 has no effect if the server does not also support it.

  • ,

    shell> mysql
    
    089

    Enable named commands. Long-format commands are permitted, not just short-format commands. For example,

    shell> mysql
    
    090 and
    shell> mysql
    
    091 both are recognized. Use to disable named commands. See .

  • ,

    shell> mysql
    
    094

    This has the same effect as

    shell> mysql
    
    095. See the description for .

  • ,

    shell> mysql
    
    098

    Do not beep when errors occur.

  • ,

    shell> mysql
    
    100

    Ignore statements except those that occur while the default database is the one named on the command line. This option is rudimentary and should be used with care. Statement filtering is based only on statements.

    Initially, executes statements in the input because specifying a database

    shell> mysql
    
    102 on the command line is equivalent to inserting at the beginning of the input. Then, for each statement encountered, accepts or rejects following statements depending on whether the database named is the one on the command line. The content of the statements is immaterial.

    Suppose that is invoked to process this set of statements:

    shell> mysql --host=localhost
    
    5

    If the command line is , handles the input as follows:

    • The statement is executed because the default database is

      shell> mysql
      
      106, even though the statement names a table in a different database.

    • The and statements are not executed because the default database is not

      shell> mysql
      
      106, even though the statements name a table in
      shell> mysql
      
      106.

    • The and statements are executed because the default database is

      shell> mysql
      
      106, even though the statement names a table in a different database.

  • Use the given command for paging query output. If the command is omitted, the default pager is the value of your

    shell> mysql
    
    116 environment variable. Valid pagers are less, more, cat [> filename], and so forth. This option works only on Unix and only in interactive mode. To disable paging, use . , discusses output paging further.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for the connection.

  • Set the prompt to the specified format. The default is

    shell> mysql
    
    131. The special sequences that the prompt can contain are described in .

  • The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • ,

    shell> mysql
    
    134

    Do not cache each query result, print each row as it is received. This may slow down the server if the output is suspended. With this option, does not use the history file.

  • ,

    shell> mysql
    
    136

    For tabular output, the “boxing” around columns enables one column value to be distinguished from another. For nontabular output (such as is produced in batch mode or when the or option is given), special characters are escaped in the output so they can be identified easily. Newline, tab,

    shell> mysql
    
    139, and backslash are written as
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    88,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    87,
    shell> mysql
    
    028, and
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    90. The option disables this character escaping.

    The following example demonstrates tabular versus nontabular output and the use of raw mode to disable escaping:

    shell> mysql --host=localhost
    
    6
  • If the connection to the server is lost, automatically try to reconnect. A single reconnect attempt is made each time the connection is lost. To suppress reconnection behavior, use .

  • , ,

    shell> mysql
    
    149

    Permit only those and statements that specify which rows to modify by using key values. If you have set this option in an option file, you can override it by using on the command line. See , for more information about this option.

  • Do not send passwords to the server in old (pre-4.1.1) format. This prevents connections except for servers that use the newer password format. As of MySQL 5.6.7, this option is enabled by default; use to disable it.

  • The path name to a file containing the server RSA public key. The file must be in PEM format. The public key is used for RSA encryption of the client password for connections to the server made using accounts that authenticate with the

    shell> mysql
    
    156 plugin. This option is ignored for client accounts that do not authenticate with that plugin. It is also ignored if password encryption is not needed, as is the case when the client connects to the server using an SSL connection.

    The server sends the public key to the client as needed, so it is not necessary to use this option for RSA password encryption to occur. It is more efficient to do so because then the server need not send the key.

    For additional discussion regarding use of the

    shell> mysql
    
    156 plugin, including how to get the RSA public key, see .

    This option is available only if MySQL was built using OpenSSL. It was added in MySQL 5.6.6 under the name

    shell> mysql
    
    158 and renamed in 5.6.7 to
    shell> mysql
    
    159.

  • Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode.

  • Ignore

    shell> mysql
    
    162 signals (typically the result of typing Control+C).

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. Produce less output. This option can be given multiple times to produce less and less output.

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

  • ,

    shell> mysql
    
    167

    Do not write column names in results.

  • ,

    shell> mysql
    
    169

    Do not write line numbers for errors. Useful when you want to compare result files that include error messages.

  • ,

    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with specify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See .

  • ,

    shell> mysql
    
    176

    Display output in table format. This is the default for interactive use, but can be used to produce table output in batch mode.

  • Append a copy of output to the given file. This option works only in interactive mode. , discusses tee files further.

  • ,

    shell> mysql
    
    179

    Flush the buffer after each query.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Produce more output about what the program does. This option can be given multiple times to produce more and more output. (For example,

    shell> mysql
    
    184 produces table output format even in batch mode.)

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • ,

    shell> mysql
    
    188

    Print query output rows vertically (one line per column value). Without this option, you can specify vertical output for individual statements by terminating them with

    shell> mysql
    
    010.

  • ,

    shell> mysql
    
    191

    If the connection cannot be established, wait and retry instead of aborting.

  • ,

    shell> mysql
    
    193

    Produce XML output.

    shell> mysql --host=localhost
    
    7

    The output when is used with matches that of . See for details.

    The XML output also uses an XML namespace, as shown here:

    shell> mysql --host=localhost
    
    8

    (See Bug #25946.)

You can also set the following variables by using

shell> mysql
196=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81.

  • shell> mysql
    
    198

    The number of seconds before connection timeout. (Default value is

    shell> mysql
    
    199.)

  • shell> mysql --host=remote.example.com
    
    15

    The maximum packet length to send to or receive from the server. (Default value is 16MB.)

  • The automatic limit for rows in a join when using . (Default value is 1,000,000.)

  • The buffer size for TCP/IP and socket communication. (Default value is 16KB.)

  • shell> mysql
    
    204

    The automatic limit for statements when using . (Default value is 1,000.)

sends each SQL statement that you issue to the server to be executed. There is also a set of commands that itself interprets. For a list of these commands, type

shell> mysql
207 or
shell> mysql
208 at the
shell> mysql
131 prompt:

shell> mysql --host=localhost
9

If is invoked with the option, all commands are disabled except

shell> mysql
030 and
shell> mysql
031 in non-interactive mode (for input piped to or loaded using the
shell> mysql
032 command).

Each command has both a long and short form. The long form is not case sensitive; the short form is. The long form can be followed by an optional semicolon terminator, but the short form should not.

The use of short-form commands within multi-line

shell> mysql
214 comments is not supported.

  • shell> mysql
    
    215],
    shell> mysql
    
    216],
    shell> mysql
    
    217],
    shell> mysql
    
    218]

    Display a help message listing the available commands.

    If you provide an argument to the

    shell> mysql
    
    207 command, uses it as a search string to access server-side help from the contents of the MySQL Reference Manual. For more information, see .

  • charset

    shell> mysql
    
    054, \C
    shell> mysql
    
    054

    Change the default character set and issue a

    shell> mysql
    
    222 statement. This enables the character set to remain synchronized on the client and server if is run with auto-reconnect enabled (which is not recommended), because the specified character set is used for reconnects.

  • shell> mysql
    
    223,
    shell> mysql
    
    224

    Clear the current input. Use this if you change your mind about executing the statement that you are entering.

  • connect [

    shell> mysql
    
    102
    shell> mysql --host=remote.example.com
    
    83]]
    , \r [
    shell> mysql
    
    102
    shell> mysql --host=remote.example.com
    
    83]]

    Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.

  • delimiter

    shell> mysql --host=remote.example.com
    
    42, \d
    shell> mysql --host=remote.example.com
    
    42

    Change the string that interprets as the separator between SQL statements. The default is the semicolon character (“

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”).

    The delimiter string can be specified as an unquoted or quoted argument on the

    shell> mysql
    
    031 command line. Quoting can be done with either single quote (
    shell> mysql
    
    233), double quote (
    shell> mysql
    
    234), or backtick (
    shell> mysql
    
    235) characters. To include a quote within a quoted string, either quote the string with a different quote character or escape the quote with a backslash (“
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    95”) character. Backslash should be avoided outside of quoted strings because it is the escape character for MySQL. For an unquoted argument, the delimiter is read up to the first space or end of line. For a quoted argument, the delimiter is read up to the matching quote on the line.

    interprets instances of the delimiter string as a statement delimiter anywhere it occurs, except within quoted strings. Be careful about defining a delimiter that might occur within other words. For example, if you define the delimiter as

    shell> mysql
    
    237, you will be unable to use the word
    shell> mysql
    
    238 in statements. interprets this as
    shell> mysql
    
    239 followed by the delimiter
    shell> mysql
    
    237.

    When the delimiter recognized by is set to something other than the default of “

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”, instances of that character are sent to the server without interpretation. However, the server itself still interprets “
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74” as a statement delimiter and processes statements accordingly. This behavior on the server side comes into play for multiple-statement execution (see ), and for parsing the body of stored procedures and functions, triggers, and events (see ).

  • shell> mysql
    
    243,
    shell> mysql
    
    244

    Edit the current input statement. checks the values of the

    shell> mysql
    
    245 and
    shell> mysql
    
    246 environment variables to determine which editor to use. The default editor is vi if neither variable is set.

    The

    shell> mysql
    
    243 command works only in Unix.

  • shell> mysql
    
    248,
    shell> mysql
    
    010

    Send the current statement to the server to be executed and display the result using vertical format.

  • shell> mysql
    
    250,
    shell> mysql
    
    091

    Exit .

  • shell> mysql
    
    252,
    shell> mysql
    
    009

    Send the current statement to the server to be executed.

  • shell> mysql
    
    254,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    88

    Disable output paging. See the description for

    shell> mysql
    
    256.

    The

    shell> mysql
    
    254 command works only in Unix.

  • shell> mysql
    
    258,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    87

    Disable output copying to the tee file. See the description for

    shell> mysql
    
    260.

  • shell> mysql
    
    261,
    shell> mysql
    
    262

    Enable display of warnings after each statement.

  • shell> mysql
    
    263],
    shell> mysql
    
    264]

    Enable output paging. By using the option when you invoke , it is possible to browse or search query results in interactive mode with Unix programs such as less, more, or any other similar program. If you specify no value for the option, checks the value of the

    shell> mysql
    
    116 environment variable and sets the pager to that. Pager functionality works only in interactive mode.

    Output paging can be enabled interactively with the

    shell> mysql
    
    256 command and disabled with
    shell> mysql
    
    254. The command takes an optional argument; if given, the paging program is set to that. With no argument, the pager is set to the pager that was set on the command line, or
    shell> mysql --port=13306 --host=localhost
    
    26 if no pager was specified.

    Output paging works only in Unix because it uses the

    shell> mysql
    
    270 function, which does not exist on Windows. For Windows, the
    shell> mysql
    
    260 option can be used instead to save query output, although it is not as convenient as
    shell> mysql
    
    256 for browsing output in some situations.

  • shell> mysql
    
    273,
    shell> mysql
    
    274

    Print the current input statement without executing it.

  • prompt [

    shell> mysql --host=remote.example.com
    
    42], \R [
    shell> mysql --host=remote.example.com
    
    42]

    Reconfigure the prompt to the given string. The special character sequences that can be used in the prompt are described later in this section.

    If you specify the

    shell> mysql
    
    277 command with no argument, resets the prompt to the default of
    shell> mysql
    
    131.

  • shell> mysql
    
    090,
    shell> mysql
    
    091

    Exit .

  • shell> mysql
    
    017,
    shell> mysql
    
    282

    Rebuild the completion hash that enables database, table, and column name completion while you are entering statements. (See the description for the option.)

  • source

    shell> mysql --host=remote.example.com
    
    38, \.
    shell> mysql --host=remote.example.com
    
    38

    Read the named file and executes the statements contained therein. On Windows, you can specify path name separators as

    shell> mysql --host=remote.example.com
    
    04 or
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    90.

  • shell> mysql
    
    288,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    91

    Provide status information about the connection and the server you are using. If you are running in mode,

    shell> mysql
    
    288 also prints the values for the variables that affect your queries.

  • shell> mysql
    
    292,
    shell> mysql
    
    293

    Execute the given command using your default command interpreter.

    The

    shell> mysql
    
    294 command works only in Unix.

  • tee [

    shell> mysql --host=remote.example.com
    
    38], \T [
    shell> mysql --host=remote.example.com
    
    38]

    By using the option when you invoke , you can log statements and their output. All the data displayed on the screen is appended into a given file. This can be very useful for debugging purposes also. flushes results to the file after each statement, just before it prints its next prompt. Tee functionality works only in interactive mode.

    You can enable this feature interactively with the

    shell> mysql
    
    260 command. Without a parameter, the previous file is used. The
    shell> mysql
    
    260 file can be disabled with the
    shell> mysql
    
    258 command. Executing
    shell> mysql
    
    260 again re-enables logging.

  • use

    shell> mysql
    
    102, \u
    shell> mysql
    
    102

    Use

    shell> mysql
    
    102 as the default database.

  • shell> mysql
    
    305,
    shell> mysql
    
    306

    Enable display of warnings after each statement (if there are any).

Here are a few tips about the

shell> mysql
256 command:

  • You can use it to write to a file and the results go only to the file:

    shell> mysql
    
    00

    You can also pass any options for the program that you want to use as your pager:

    shell> mysql
    
    01
  • In the preceding example, note the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    75 option. You may find it very useful for browsing wide query results. Sometimes a very wide result set is difficult to read on the screen. The
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    75 option to less can make the result set much more readable because you can scroll it horizontally using the left-arrow and right-arrow keys. You can also use
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    75 interactively within less to switch the horizontal-browse mode on and off. For more information, read the less manual page:

    shell> mysql
    
    02
  • The

    shell> mysql
    
    311 and
    shell> mysql
    
    193 options may be used with less to cause it to exit if output fits on one screen, which is convenient when no scrolling is necessary:

    shell> mysql
    
    03
  • You can specify very complex pager commands for handling query output:

    shell> mysql
    
    04

    In this example, the command would send query results to two files in two different directories on two different file systems mounted on

    shell> mysql
    
    313 and
    shell> mysql
    
    314, yet still display the results onscreen using less.

You can also combine the

shell> mysql
260 and
shell> mysql
256 functions. Have a
shell> mysql
260 file enabled and
shell> mysql
256 set to less, and you are able to browse the results using the less program and still have everything appended into a file the same time. The difference between the Unix
shell> mysql
260 used with the
shell> mysql
256 command and the built-in
shell> mysql
260 command is that the built-in
shell> mysql
260 works even if you do not have the Unix tee available. The built-in
shell> mysql
260 also logs everything that is printed on the screen, whereas the Unix tee used with
shell> mysql
256 does not log quite that much. Additionally,
shell> mysql
260 file logging can be turned on and off interactively from within . This is useful when you want to log some queries to a file, but not others.

The

shell> mysql
277 command reconfigures the default
shell> mysql
131 prompt. The string for defining the prompt can contain the following special sequences.

OptionDescription

shell> mysql
224A counter that increments for each statement you issue
shell> mysql
329The full current date
shell> mysql
330The default database
shell> mysql
208The server host
shell> mysql
332The current delimiter
shell> mysql
333Minutes of the current time
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
88A newline character
shell> mysql
335The current month in three-letter format (Jan, Feb, …)
shell> mysql
336The current month in numeric format
shell> mysql
337am/pm
shell> mysql
274The current TCP/IP port or socket file
shell> mysql
339The current time, in 24-hour military time (0–23)
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
89The current time, standard 12-hour time (1–12)
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
93Semicolon
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
91Seconds of the current time
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
87A tab character
shell> mysql
344

Your full

shell> mysql --port=13306 --host=localhost
01@
shell> mysql --host=remote.example.com
83
account name

shell> mysql
347Your user name
shell> mysql
348The server version
shell> mysql
262The current day of the week in three-letter format (Mon, Tue, …)
shell> mysql
350The current year, four digits
shell> mysql
351The current year, two digits
shell> mysql
352A space
shell> mysql
353A space (a space follows the backslash)
shell> mysql
354Single quote
shell> mysql
355Double quote
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
90A literal “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
95” backslash character\
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96, for any “
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
96” not listed above

You can set the prompt in several ways:

  • Use an environment variable. You can set the

    shell> mysql
    
    361 environment variable to a prompt string. For example:

    shell> mysql
    
    05
  • Use a command-line option. You can set the option on the command line to . For example:

    shell> mysql
    
    06
  • Use an option file. You can set the

    shell> mysql
    
    277 option in the
    shell> mysql --host=remote.example.com
    
    08 group of any MySQL option file, such as
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    27 or the
    shell> mysql
    
    366 file in your home directory. For example:

    shell> mysql
    
    07

    In this example, note that the backslashes are doubled. If you set the prompt using the

    shell> mysql
    
    277 option in an option file, it is advisable to double the backslashes when using the special prompt options. There is some overlap in the set of permissible prompt options and the set of special escape sequences that are recognized in option files. (The rules for escape sequences in option files are listed in .) The overlap may cause you problems if you use single backslashes. For example,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    91 is interpreted as a space rather than as the current seconds value. The following example shows how to define a prompt within an option file to include the current time in
    shell> mysql
    
    369 format:

    shell> mysql
    
    08
  • Set the prompt interactively. You can change your prompt interactively by using the

    shell> mysql
    
    277 (or
    shell> mysql
    
    339) command. For example:

    shell> mysql
    
    09

4.5.1.3. mysql History File

On Unix, the client writes a record of executed statements to a history file. By default, this file is named

shell> mysql
372 and is created in your home directory. To specify a different file, set the value of the
shell> mysql
373 environment variable.

The

shell> mysql
372 should be protected with a restrictive access mode because sensitive information might be written to it, such as the text of SQL statements that contain passwords. See .

does not write statements to the history file when used noninteractively (for example, when reading input from a file or a pipe). It is also possible to explicitly suppress logging of statements to the history file by using the or option.

If you do not want to maintain a history file, first remove

shell> mysql
372 if it exists, and then use either of the following techniques:

  • Set the

    shell> mysql
    
    373 variable to
    shell> mysql
    
    379. To cause this setting to take effect each time you log in, put the setting in one of your shell's startup files.

  • Create

    shell> mysql
    
    372 as a symbolic link to
    shell> mysql
    
    379:

    shell> mysql
    
    10

    You need do this only once.

As of MySQL 5.6.8, ignores for logging purposes statements that match any pattern in the “ignore” list. By default, the pattern list is

shell> mysql
382, to ignore statements that refer to passwords. Pattern matching is not case sensitive. Within patterns, two characters are special:

  • shell> mysql
    
    383 matches any single character.

  • shell> mysql
    
    384 matches any sequence of zero or more characters

To specify additional patterns, use the command option or set the

shell> mysql
386 environment variable. (If both are specified, the option value takes precedence.) The value should be a colon-separated list of one or more patterns, which are appended to the default pattern list.

Patterns specified on the command line might need to be quoted or escaped to prevent your command interpreter from treating them specially. For example, to suppress logging for

shell> mysql
150 and
shell> mysql
105 statements in addition to statements that refer to passwords, invoke like this:

shell> mysql
11

4.5.1.4. mysql Server-Side Help

shell> mysql
12

If you provide an argument to the

shell> mysql
207 command, uses it as a search string to access server-side help from the contents of the MySQL Reference Manual. The proper operation of this command requires that the help tables in the
shell> mysql --port=13306 --host=localhost
33 database be initialized with help topic information (see ).

If there is no match for the search string, the search fails:

shell> mysql
13

Use to see a list of the help categories:

shell> mysql
14

If the search string matches multiple items, shows a list of matching topics:

shell> mysql
15

Use a topic as the search string to see the help entry for that topic:

shell> mysql
16

4.5.1.5. Executing SQL Statements from a Text File

The client typically is used interactively, like this:

shell> mysql --host=localhost
2

However, it is also possible to put your SQL statements in a file and then tell to read its input from that file. To do so, create a text file

shell> mysql
391 that contains the statements you wish to execute. Then invoke as shown here:

shell> mysql
18

If you place a USE

shell> mysql
102 statement as the first statement in the file, it is unnecessary to specify the database name on the command line:

shell> mysql
19

If you are already running , you can execute an SQL script file using the

shell> mysql
032 command or
shell> mysql
394 command:

shell> mysql
20

Sometimes you may want your script to display progress information to the user. For this you can insert statements like this:

shell> mysql
21

The statement shown outputs

shell> mysql
395.

You can also invoke with the option, which causes each statement to be displayed before the result that it produces.

ignores Unicode byte order mark (BOM) characters at the beginning of input files. Previously, it read them and sent them to the server, resulting in a syntax error. Presence of a BOM does not cause to change its default character set. To do that, invoke with an option such as .

For more information about batch mode, see .

This section describes some techniques that can help you use more effectively.

4.5.1.6.1. Unicode Support on Windows

Windows provides APIs based on UTF-16LE for reading from and writing to the console. As of MySQL 5.6.2, the client for Windows is able to use these APIs. As of 5.6.3, the Windows installer creates an item in the MySQL menu named

shell> mysql
398. This item invokes the client with properties set to communicate through the console to the MySQL server using Unicode.

To take advantage of this support manually, run within a console that uses a compatible Unicode font and set the default character set to a Unicode character set that is supported for communication with the server:

  1. Open a console window.

  2. Go to the console window properties, select the font tab, and choose Lucida Console or some other compatible Unicode font. This is necessary because console windows start by default using a DOS raster font that is inadequate for Unicode.

  3. Execute with the (or

    shell> mysql
    
    400) option. This option is necessary because
    shell> mysql
    
    401 is not supported as a connection character set.

With those changes, will use the Windows APIs to communicate with the console using UTF-16LE, and communicate with the server using UTF-8. (The menu item mentioned previously sets the font and character set as just described.)

To avoid those steps each time you run , you can create a shortcut that invokes . The shortcut should set the console font to Lucida Console or some other compatible Unicode font, and pass the (or

shell> mysql
400) option to .

Alternatively, create a shortcut that only sets the console font, and set the character set in the

shell> mysql --host=remote.example.com
08 group of your
shell> mysql
405 file:

shell> mysql
22

4.5.1.6.2. Displaying Query Results Vertically

Some query results are much more readable when displayed vertically, instead of in the usual horizontal table format. Queries can be displayed vertically by terminating the query with \G instead of a semicolon. For example, longer text values that include newlines often are much easier to read with vertical output:

shell> mysql
23

For beginners, a useful startup option is (or , which has the same effect). It is helpful for cases when you might have issued a

shell> mysql
408 statement but forgotten the
shell> mysql
409 clause. Normally, such a statement deletes all rows from the table. With , you can delete rows only by specifying the key values that identify them. This helps prevent accidents.

When you use the option, issues the following statement when it connects to the MySQL server:

shell> mysql
24

See .

The statement has the following effects:

  • You are not permitted to execute an or statement unless you specify a key constraint in the

    shell> mysql
    
    409 clause or provide a
    shell> mysql
    
    416 clause (or both). For example:

    shell> mysql
    
    25
  • The server limits all large results to 1,000 rows unless the statement includes a

    shell> mysql
    
    416 clause.

  • The server aborts multiple-table statements that probably need to examine more than 1,000,000 row combinations.

To specify limits different from 1,000 and 1,000,000, you can override the defaults by using the

shell> mysql
420 and
shell> mysql
421 options:

shell> mysql
26

4.5.1.6.4. Disabling mysql Auto-Reconnect

If the client loses its connection to the server while sending a statement, it immediately and automatically tries to reconnect once to the server and send the statement again. However, even if succeeds in reconnecting, your first connection has ended and all your previous session objects and settings are lost: temporary tables, the autocommit mode, and user-defined and session variables. Also, any current transaction rolls back. This behavior may be dangerous for you, as in the following example where the server was shut down and restarted between the first and second statements without you knowing it:

shell> mysql
27

The

shell> mysql
422 user variable has been lost with the connection, and after the reconnection it is undefined. If it is important to have terminate with an error if the connection has been lost, you can start the client with the option.

For more information about auto-reconnect and its effect on state information when a reconnection occurs, see .

4.5.2. mysqladmin — Client for Administering a MySQL Server

is a client for performing administrative operations. You can use it to check the server's configuration and current status, to create and drop databases, and more.

Invoke like this:

shell> mysql
28

supports the following commands. Some of the commands take an argument following the command name.

  • create

    shell> mysql
    
    102

    Create a new database named

    shell> mysql
    
    102.

  • shell> mysql
    
    426

    Tell the server to write debug information to the error log.

    This includes information about the Event Scheduler. See .

  • drop

    shell> mysql
    
    102

    Delete the database named

    shell> mysql
    
    102 and all its tables.

  • shell> mysql
    
    429

    Display the server status variables and their values.

  • shell> mysql
    
    430

    Flush all information in the host cache.

  • shell> mysql
    
    431

    Flush all logs.

  • shell> mysql
    
    432

    Reload the grant tables (same as

    shell> mysql --port=13306 --host=localhost
    
    46).

  • shell> mysql
    
    434

    Clear status variables.

  • shell> mysql
    
    435

    Flush all tables.

  • shell> mysql
    
    436

    Flush the thread cache.

  • shell> mysql
    
    437,
    shell> mysql
    
    438,...

    Kill server threads. If multiple thread ID values are given, there must be no spaces in the list.

  • shell> mysql
    
    439

    This is like the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 command but stores the password using the old (pre-4.1) password-hashing format. (See .)

  • shell> mysql
    
    441

    Set a new password. This changes the password to

    shell> mysql
    
    442 for the account that you use with for connecting to the server. Thus, the next time you invoke (or any other client program) using the same account, you will need to specify the new password.

    If the

    shell> mysql
    
    442 value contains spaces or other characters that are special to your command interpreter, you need to enclose it within quotation marks. On Windows, be sure to use double quotation marks rather than single quotation marks; single quotation marks are not stripped from the password, but rather are interpreted as part of the password. For example:

    shell> mysql
    
    29

    In MySQL 5.6, the new password can be omitted following the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 command. In this case, prompts for the password value, which enables you to avoid specifying the password on the command line. Omitting the password value should be done only if
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 is the final command on the command line. Otherwise, the next argument is taken as the password.

    Do not use this command used if the server was started with the option. No password change will be applied. This is true even if you precede the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 command with
    shell> mysql
    
    432 on the same command line to re-enable the grant tables because the flush operation occurs after you connect. However, you can use to re-enable the grant table and then use a separate command to change the password.

  • shell> mysql
    
    449

    Check whether the server is available. The return status from is 0 if the server is running, 1 if it is not. This is 0 even in case of an error such as

    shell> mysql
    
    450, because this means that the server is running but refused the connection, which is different from the server not running.

  • shell> mysql
    
    451

    Show a list of active server threads. This is like the output of the statement. If the option is given, the output is like that of . (See .)

  • shell> mysql --port=13306 --host=localhost
    
    46

    Reload the grant tables.

  • shell> mysql
    
    457

    Flush all tables and close and open log files.

  • shell> mysql
    
    458

    Stop the server.

  • shell> mysql
    
    459

    Start replication on a slave server.

  • shell> mysql
    
    288

    Display a short server status message.

  • shell> mysql
    
    461

    Stop replication on a slave server.

  • shell> mysql
    
    462

    Display the server system variables and their values.

  • shell> mysql
    
    463

    Display version information from the server.

All commands can be shortened to any unique prefix. For example:

shell> mysql
30

The command result displays the following values:

  • The number of seconds the MySQL server has been running.

  • shell> mysql
    
    465

    The number of active threads (clients).

  • The number of questions (queries) from clients since the server was started.

  • shell> mysql
    
    467

    The number of queries that have taken more than seconds. See .

  • shell> mysql
    
    469

    The number of tables the server has opened.

  • shell> mysql
    
    470

    The number of

    shell> mysql
    
    471,
    shell> mysql
    
    457, and
    shell> mysql --port=13306 --host=localhost
    
    46 commands the server has executed.

  • shell> mysql
    
    474

    The number of tables that currently are open.

If you execute when connecting to a local server using a Unix socket file, waits until the server's process ID file has been removed, to ensure that the server has stopped properly.

supports the following options, which can be specified on the command line or in the

shell> mysql --host=remote.example.com
33 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.4. 

shell> mysql
477 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

    This option is supported beginning with MySQL 5.6.1.

  • The directory where character sets are installed. See .

  • ,

    shell> mysql
    
    041

    Compress all information sent between the client and the server if both support compression.

  • , -c

    shell> mysql --port=13306 --host=localhost
    
    41

    The number of iterations to make for repeated command execution if the option is given.

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql
    
    491.

  • Print some debugging information when the program exits.

  • Print debugging information and memory and CPU usage statistics when the program exits.

  • The client-side authentication plugin to use. See .

  • Use

    shell> mysql
    
    054 as the default character set. See .

  • Enable the

    shell> mysql
    
    063 cleartext authentication plugin. (See .) This option was added in MySQL 5.6.7.

  • ,

    shell> mysql
    
    068

    Do not ask for confirmation for the drop

    shell> mysql
    
    102 command. With multiple commands, continue even if an error occurs.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Connect to the MySQL server on the given host.

  • ,

    shell> mysql
    
    098

    Suppress the warning beep that is emitted by default for errors such as a failure to connect to the server.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for the connection.

  • The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • ,

    shell> mysql
    
    136

    Show the difference between the current and previous values when used with the option. This option works only with the

    shell> mysql
    
    429 command.

  • ,

    shell> mysql --host=localhost
    
    95

    Exit silently if a connection to the server cannot be established.

  • ,

    shell> mysql
    
    526

    Execute commands repeatedly, sleeping for

    shell> mysql
    
    527 seconds in between. The option determines the number of iterations. If is not given, executes commands indefinitely until interrupted.

  • ,

    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with specify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • ,

    shell> mysql
    
    188

    Print output vertically. This is similar to , but prints output vertically.

  • ,

    shell> mysql
    
    545]

    If the connection cannot be established, wait and retry instead of aborting. If a

    shell> mysql
    
    546 value is given, it indicates the number of times to retry. The default is one time.

You can also set the following variables by using

shell> mysql
196=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81.

  • shell> mysql
    
    198

    The maximum number of seconds before connection timeout. The default value is 43200 (12 hours).

  • shell> mysql
    
    550

    The maximum number of seconds to wait for server shutdown. The default value is 3600 (1 hour).

4.5.3. mysqlcheck — A Table Maintenance Program

The client performs table maintenance: It checks, repairs, optimizes, or analyzes tables.

Each table is locked and therefore unavailable to other sessions while it is being processed, although for check operations, the table is locked with a

shell> mysql
551 lock only (see , for more information about
shell> mysql
551 and
shell> mysql
555 locks). Table maintenance operations can be time-consuming, particularly for large tables. If you use the or option to process all tables in one or more databases, an invocation of might take a long time. (This is also true for because that program invokes to check all tables and repair them if necessary.)

is similar in function to , but works differently. The main operational difference is that must be used when the server is running, whereas should be used when it is not. The benefit of using is that you do not have to stop the server to perform table maintenance.

uses the SQL statements , , , and in a convenient way for the user. It determines which statements to use for the operation you want to perform, and then sends the statements to the server to be executed. For details about which storage engines each statement works with, see the descriptions for those statements in .

The

shell> mysql
004 storage engine supports all four maintenance operations, so can be used to perform any of them on
shell> mysql
004 tables. Other storage engines do not necessarily support all operations. In such cases, an error message is displayed. For example, if
shell> mysql
564 is a
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
36 table, an attempt to check it produces this result:

shell> mysql
31

If is unable to repair a table, see for manual table repair strategies. This will be the case, for example, for

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 tables, which can be checked with , but not repaired with .

It is best to make a backup of a table before performing a table repair operation; under some circumstances the operation might cause data loss. Possible causes include but are not limited to file system errors.

There are three general ways to invoke :

shell> mysql
32

If you do not name any tables following

shell> mysql
102 or if you use the or option, entire databases are checked.

has a special feature compared to other client programs. The default behavior of checking tables () can be changed by renaming the binary. If you want to have a tool that repairs tables by default, you should just make a copy of named mysqlrepair, or make a symbolic link to named mysqlrepair. If you invoke mysqlrepair, it repairs tables.

The names shown in the following table can be used to change default behavior.

CommandMeaningmysqlrepairThe default option is mysqlanalyzeThe default option is mysqloptimizeThe default option is

supports the following options, which can be specified on the command line or in the

shell> mysql
576 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.5. 

shell> mysql
578 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql
    
    094

    Check all tables in all databases. This is the same as using the option and naming all the databases on the command line.

  • ,

    shell> mysql
    
    585

    Instead of issuing a statement for each table, execute a single statement for each database that names all the tables from that database to be processed.

  • ,

    shell> mysql
    
    587

    Analyze the tables.

  • If a checked table is corrupted, automatically fix it. Any necessary repairs are done after all tables have been checked.

  • shell> mysql
    
    033

    On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

    This option is supported beginning with MySQL 5.6.1.

  • The directory where character sets are installed. See .

  • ,

    shell> mysql
    
    039

    Check the tables for errors. This is the default operation.

  • ,

    shell> mysql
    
    041

    Check only tables that have changed since the last check or that have not been closed properly.

  • ,

    shell> mysql
    
    596

    Invoke with the

    shell> mysql --host=localhost
    
    71 option to check tables for incompatibilities with the current version of the server. This option automatically enables the and options.

  • Compress all information sent between the client and the server if both support compression.

  • ,

    shell> mysql
    
    022

    Process all tables in the named databases. Normally, treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names.

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql
    
    608.

  • Print some debugging information when the program exits.

  • Print debugging information and memory and CPU usage statistics when the program exits.

  • Use

    shell> mysql
    
    054 as the default character set. See .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    83

    If you are using this option to check tables, it ensures that they are 100% consistent but takes a long time.

    If you are using this option to repair tables, it runs an extended repair that may not only take a long time to execute, but may produce a lot of garbage rows also!

  • The client-side authentication plugin to use. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql
    
    311

    Check only tables that have not been closed properly.

  • Convert database names to 5.1 format. Only database names that contain special characters are affected.

  • Convert table names to 5.1 format. Only table names that contain special characters are affected. This option also applies to views.

  • ,

    shell> mysql
    
    068

    Continue even if an SQL error occurs.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Connect to the MySQL server on the given host.

  • ,

    shell> mysql
    
    037

    Do a check that is faster than an operation. This finds only 99.99% of all errors, which should be good enough in most cases.

  • ,

    shell> mysql
    
    100

    Optimize the tables.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for the connection.

  • The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • ,

    shell> mysql
    
    134

    If you are using this option to check tables, it prevents the check from scanning the rows to check for incorrect links. This is the fastest check method.

    If you are using this option to repair tables, it tries to repair only the index tree. This is the fastest repair method.

  • ,

    shell> mysql
    
    136

    Perform a repair that can fix almost anything except unique keys that are not unique.

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. Print only error messages.

  • ,

    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    46 specify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See .

  • Override the or

    shell> mysql
    
    022 option. All name arguments following the option are regarded as table names.

  • For repair operations on

    shell> mysql
    
    004 tables, get the table structure from the
    shell> mysql
    
    658 file so that the table can be repaired even if the
    shell> mysql
    
    659 header is corrupted.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print information about the various stages of program operation.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • This option is enabled by default, so that , , and statements generated by are written to the binary log. Use to cause

    shell> mysql
    
    671 to be added to the statements so that they are not logged. Use the when these statements should not be sent to replication slaves or run when using the binary logs for recovery from backup.

4.5.4. mysqldump — A Database Backup Program

The client is a utility that performs , producing a set of SQL statements that can be run to reproduce the original schema objects, table data, or both. It dumps one or more MySQL database for backup or transfer to another SQL server. The command can also generate output in CSV, other delimited text, or XML format.

requires at least the privilege for dumped tables, for dumped views, and if the option is not used. Certain options might require other privileges as noted in the option descriptions.

Performance and Scalability Considerations

shell> mysql
677 advantages include the convenience and flexibility of viewing or even editing the output before restoring. You can clone databases for development and DBA work, or produce slight variations of an existing database for testing. It is not intended as a fast or scalable solution for backing up substantial amounts of data. With large data sizes, even if the backup step takes a reasonable time, restoring the data can be very slow because replaying the SQL statements involves disk I/O for insertion, index creation, and so on.

For large-scale backup and restore, a backup is more appropriate, to copy the data files in their original format that can be restored quickly:

  • If your tables are primarily

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42 tables, or if you have a mix of
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42 and
    shell> mysql
    
    004 tables, consider using the mysqlbackup command of the MySQL Enterprise Backup product. (Available as part of the Enterprise subscription.) It provides the best performance for
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42 backups with minimal disruption; it can also back up tables from
    shell> mysql
    
    004 and other storage engines; and it provides a number of convenient options to accommodate different backup scenarios. See MySQL Enterprise Backup User's Guide (Version 3.8.1).

  • If your tables are primarily

    shell> mysql
    
    004 tables, consider using the instead, for better performance than of backup and restore operations. See .

can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it. Buffering in memory can be a problem if you are dumping large tables. To dump tables row by row, use the option (or , which enables ). The option (and hence ) is enabled by default, so to enable memory buffering, use .

If you are using a recent version of to generate a dump to be reloaded into a very old MySQL server, use the option instead of the or option.

For additional information about , see .

Syntax

There are three general ways to invoke , to dump progressively more data:

shell> mysql
33

To dump entire databases, do not name any tables following

shell> mysql
102, or use the or option.

To see a list of the options your version of supports, issue the command .

Option Syntax - Alphabetical Summary

supports the following options, which can be specified on the command line or in the

shell> mysql
696 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.6. 

shell> mysql
677 Options


Connection Options

The command logs into a MySQL server to extract information. The following options specify how to connect to the MySQL server, either on the same machine or a remote system.

  • On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

    This option is supported beginning with MySQL 5.6.1.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    55,
    shell> mysql
    
    041

    Compress all information sent between the client and the server if both support compression.

  • --default-auth=

    shell> mysql --host=localhost
    
    02

    The client-side authentication plugin to use. See .

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    16,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Dump data from the MySQL server on the given host. The default host is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52.

  • --password[=

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06], -p[
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    70 or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    07,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.

  • shell> mysql --host=localhost
    
    42

    The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    26,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for the connection.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    28

    The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • shell> mysql --host=remote.example.com --port=13306
    
    81,
    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with specify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See .

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    47,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

You can also set the following variables by using

shell> mysql
196=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81 syntax:

  • shell> mysql --host=remote.example.com
    
    15

    The maximum size of the buffer for client/server communication. The maximum is 1GB.

  • shell> mysql
    
    203

    The initial size of the buffer for client/server communication. When creating multiple-row statements (as with the or option), creates rows up to length. If you increase this variable, ensure that the variable in the MySQL server is at least this large.

DDL Options

Usage scenarios for include setting up an entire new MySQL instance (including database tables), and replacing data inside an existing instance with existing databases and tables. The following options let you specify which things to tear down and set up when restoring a dump, by encoding various DDL statements within the dump file.

Debug Options

The following options print debugging information, encode debugging information in the dump file, or let the dump operation proceed regardless of potential problems.

  • shell> mysql
    
    735

    Permit creation of column names that are keywords. This works by prefixing each column name with the table name.

  • shell> mysql
    
    038,
    shell> mysql
    
    075

    Write additional information in the dump file such as program version, server version, and host. This option is enabled by default. To suppress this additional information, use .

  • --debug[=

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17], -# [
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default value is
    shell> mysql
    
    743.

  • shell> mysql --host=localhost
    
    84

    Print some debugging information when the program exits.

  • shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    20

    Print debugging information and memory and CPU usage statistics when the program exits.

  • shell> mysql
    
    746

    If the option is given, produces a comment at the end of the dump of the following form:

    shell> mysql
    
    34

    However, the date causes dump files taken at different times to appear to be different, even if the data are otherwise identical. and control whether the date is added to the comment. The default is (include the date in the comment). suppresses date printing.

  • shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    69,
    shell> mysql
    
    068

    Continue even if an SQL error occurs during a table dump.

    One use for this option is to cause to continue executing even when it encounters a view that has become invalid because the definition refers to a table that has been dropped. Without

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    69, exits with an error message. With
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    69, prints the error message, but it also writes an SQL comment containing the view definition to the dump output and continues executing.

  • --log-error=

    shell> mysql --host=remote.example.com
    
    38

    Log warnings and errors by appending them to the named file. The default is to do no logging.

  • shell> mysql
    
    738

    See the description for the option.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    62,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does.

Help Options

The following options display information about the command itself.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    50,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    63,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

Internationalization Options

The following options change how the command represents character data with national language settings.

  • shell> mysql
    
    034

    The directory where character sets are installed. See .

  • shell> mysql
    
    053

    Use

    shell> mysql
    
    054 as the default character set. See . If no character set is specified, uses
    shell> mysql
    
    055, and earlier versions use
    shell> mysql
    
    056.

  • shell> mysql
    
    770,
    shell> mysql
    
    167

    Turns off the setting, the same as specifying

    shell> mysql
    
    773.

  • shell> mysql
    
    772

    Add

    shell> mysql
    
    775 to the output. This option is enabled by default. To suppress the
    shell> mysql
    
    222 statement, use .

Replication Options

The command is frequently used to create an empty instance, or an instance including data, on a slave server in a replication configuration. The following options apply to dumping and restoring data on replication master and slave servers.

  • shell> mysql
    
    778

    For a slave dump produced with the option, add a statement before the statement and a statement at the end of the output.

  • shell> mysql
    
    783

    On a master replication server, delete the binary logs by sending a statement to the server after performing the dump operation. This option automatically enables .

  • --dump-slave[=

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81]

    This option is similar to except that it is used to dump a replication slave server to produce a dump file that can be used to set up another server as a slave that has the same master as the dumped server. It causes the dump output to include a statement that indicates the binary log coordinates (file name and position) of the dumped slave's master (rather than the coordinates of the dumped server, as is done by the option). These are the master server coordinates from which the slave should start replicating.

    The option value is handled the same way as for and has the same effect as

    shell> mysql
    
    785 in terms of enabling or disabling other options and in how locking is handled.

    In conjunction with

    shell> mysql
    
    779, the and options can also be used.

  • shell> mysql
    
    794

    For the statement in a slave dump produced with the option, add

    shell> mysql
    
    798 and
    shell> mysql
    
    798 options for the host name and TCP/IP port number of the slave's master.

  • --master-data[=

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81]

    Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master. It causes the dump output to include a statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

    If the option value is 2, the statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded. If the option value is 1, the statement is not written as a comment and takes effect when the dump file is reloaded. If no option value is specified, the default value is 1.

    This option requires the privilege and the binary log must be enabled.

    The

    shell> mysql
    
    785 option automatically turns off . It also turns on , unless also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for ). In all cases, any action on logs happens at the exact moment of the dump.

    It is also possible to set up a slave by dumping an existing slave of the master. To do this, use the following procedure on the existing slave:

    1. Stop the slave's SQL thread and get its current status:

      shell> mysql
      
      35
    2. From the output of the statement, the binary log coordinates of the master server from which the new slave should start replicating are the values of the

      shell> mysql
      
      810 and
      shell> mysql
      
      811 fields. Denote those values as
      shell> mysql --host=remote.example.com
      
      38 and
      shell> mysql
      
      813.

    3. Dump the slave server:

      shell> mysql
      
      36

      Using

      shell> mysql
      
      814 works only if binary logging has been enabled on the slave. Otherwise, fails with the error Binlogging on server not active. In this case you must handle any locking issues in another manner, using one or more of , , , or , as required by your application and environment.

    4. Restart the slave:

      shell> mysql
      
      37
    5. On the new slave, load the dump file:

      shell> mysql
      
      38
    6. On the new slave, set the replication coordinates to those of the master server obtained earlier:

      shell> mysql
      
      39

      The statement might also need other parameters, such as

      shell> mysql
      
      820 to point the slave to the correct master server host. Add any such parameters as necessary.

    Prior to MySQL 5.6.4, this option was required for dumping the replication log tables (see ).

  • --set-gtid-purged=

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81

    This option enables control over global transaction ID (GTID) information written to the dump file, by indicating whether to add a statement to the output.

    The following table shows the permitted option values. The default value is

    shell> mysql
    
    823.

    ValueMeaning

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    92Add no
    shell> mysql --host=remote.example.com
    
    59 statement to the output.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    90Add a
    shell> mysql --host=remote.example.com
    
    59 statement to the output. An error occurs if GTIDs are not enabled on the server.
    shell> mysql
    
    823Add a
    shell> mysql --host=remote.example.com
    
    59 statement to the output if GTIDs are enabled on the server.

    This option was added in MySQL 5.6.9.

Format Options

The following options specify how to represent the entire dump file or certain kinds of data in the dump file. They also control whether certain optional information is written to the dump file.

  • shell> mysql
    
    830

    Produce more compact output. This option enables the , , , , and options.

  • shell> mysql
    
    836

    Produce output that is more compatible with other database systems or with older MySQL servers. The value of

    shell> mysql
    
    837 can be
    shell> mysql
    
    838,
    shell> mysql
    
    839,
    shell> mysql
    
    840,
    shell> mysql
    
    841,
    shell> mysql
    
    842,
    shell> mysql
    
    843,
    shell> mysql
    
    844,
    shell> mysql
    
    845,
    shell> mysql
    
    846,
    shell> mysql
    
    847, or
    shell> mysql
    
    848. To use several values, separate them by commas. These values have the same meaning as the corresponding options for setting the server SQL mode. See .

    This option does not guarantee compatibility with other servers. It only enables those SQL mode values that are currently available for making dump output more compatible. For example,

    shell> mysql
    
    849 does not map data types to Oracle types or use Oracle comment syntax.

    This option requires a server version of 4.1.0 or higher. With older servers, it does nothing.

  • shell> mysql
    
    850,
    shell> mysql
    
    039

    Use complete statements that include column names.

  • shell> mysql
    
    853

    Include all MySQL-specific table options in the statements.

  • shell> mysql
    
    855,
    shell> mysql
    
    856,
    shell> mysql
    
    857,
    shell> mysql
    
    858

    These options are used with the option and have the same meaning as the corresponding

    shell> mysql
    
    860 clauses for . See .

  • shell> mysql
    
    863

    Dump binary columns using hexadecimal notation (for example,

    shell> mysql
    
    864 becomes
    shell> mysql
    
    865). The affected data types are , , the types, and .

  • shell> mysql
    
    870

    This option is used with the option and has the same meaning as the corresponding

    shell> mysql
    
    872 clause for . See .

  • shell> mysql
    
    875,
    shell> mysql
    
    876

    Quote identifiers (such as database, table, and column names) within “

    shell> mysql
    
    235” characters. If the SQL mode is enabled, identifiers are quoted within “
    shell> mysql
    
    234” characters. This option is enabled by default. It can be disabled with
    shell> mysql
    
    880, but this option should be given after any option such as that may enable .

  • --result-file=

    shell> mysql --host=remote.example.com
    
    38, -r
    shell> mysql --host=remote.example.com
    
    38

    Direct output to a given file. This option should be used on Windows to prevent newline “

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    88” characters from being converted to “
    shell> mysql
    
    026” carriage return/newline sequences. The result file is created and its previous contents overwritten, even if an error occurs while generating the dump.

  • shell> mysql
    
    887,
    shell> mysql
    
    888

    Produce tab-separated text-format data files. For each dumped table, creates a

    shell> mysql
    
    889.sql file that contains the statement that creates the table, and the server writes a
    shell> mysql
    
    889.txt file that contains its data. The option value is the directory in which to write the files.

    This option should be used only when is run on the same machine as the server. You must have the privilege, and the server must have permission to write files in the directory that you specify.

    By default, the

    shell> mysql
    
    893 data files are formatted using tab characters between column values and a newline at the end of each line. The format can be specified explicitly using the
    shell> mysql
    
    894 and options.

    Column values are converted to the character set specified by the option.

  • shell> mysql
    
    897

    This option enables columns to be dumped and reloaded between servers in different time zones. sets its connection time zone to UTC and adds

    shell> mysql
    
    899 to the dump file. Without this option, columns are dumped and reloaded in the time zones local to the source and destination servers, which can cause the values to change if the servers are in different time zones.
    shell> mysql
    
    897 also protects against changes due to daylight saving time.
    shell> mysql
    
    897 is enabled by default. To disable it, use
    shell> mysql
    
    903.

  • shell> mysql
    
    192,
    shell> mysql
    
    193

    Write dump output as well-formed XML.

    shell> mysql
    
    906,
    shell> mysql
    
    907, and Empty Values: For a column named
    shell> mysql
    
    908, the
    shell> mysql
    
    906 value, an empty string, and the string value
    shell> mysql
    
    907 are distinguished from one another in the output generated by this option as follows.

    Value:XML Representation:

    shell> mysql
    
    906 (unknown value)

    shell> mysql
    
    395

    shell> mysql
    
    913 (empty string)

    shell> mysql
    
    395

    shell> mysql
    
    907 (string value)

    shell> mysql
    
    906

    The output from the client when run using the option also follows the preceding rules. (See .)

    XML output from includes the XML namespace, as shown here:

    shell> mysql
    
    40

    Prior to MySQL 5.6.5, this option prevented the option from working correctly—that is, no stored routines, triggers, or events could be dumped in XML format. (Bug #11760384, Bug #52792)

Filtering Options

The following options control which kinds of schema objects are written to the dump file: by category, such as triggers or events; by name, for example, choosing which databases and tables to dump; or even filtering rows from the table data using a

shell> mysql
409 clause.

  • shell> mysql --host=localhost
    
    69,
    shell> mysql
    
    094

    Dump all tables in all databases. This is the same as using the option and naming all the databases on the command line.

    Prior to MySQL 5.6.4, the

    shell> mysql
    
    923 and
    shell> mysql
    
    924 tables (see ) were not included by this option.

  • shell> mysql
    
    556,
    shell> mysql
    
    022

    Dump several databases. Normally, treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names. and statements are included in the output before each new database.

  • shell> mysql
    
    929,
    shell> mysql
    
    188

    Include Event Scheduler events for the dumped databases in the output.

  • shell> mysql
    
    931

    Do not dump the given table, which must be specified using both the database and table names. To ignore multiple tables, use this option multiple times. This option also can be used to ignore views.

  • shell> mysql
    
    932,
    shell> mysql
    
    933

    Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the statement for the table (for example, to create an empty copy of the table by loading the dump file).

  • shell> mysql
    
    918,
    shell> mysql
    
    936

    Include stored routines (procedures and functions) for the dumped databases in the output. Use of this option requires the privilege for the

    shell> mysql
    
    938 table. The output generated by using
    shell> mysql
    
    918 contains and statements to re-create the routines. However, these statements do not include attributes such as the routine creation and modification timestamps. This means that when the routines are reloaded, they will be created with the timestamps equal to the reload time.

    If you require routines to be re-created with their original timestamp attributes, do not use

    shell> mysql
    
    918. Instead, dump and reload the contents of the
    shell> mysql
    
    938 table directly, using a MySQL account that has appropriate privileges for the
    shell> mysql --port=13306 --host=localhost
    
    33 database.

    Prior to MySQL 5.6.5, this option had no effect when used together with the option. (Bug #11760384, Bug #52792)

  • shell> mysql
    
    653

    Override the or

    shell> mysql
    
    022 option. regards all name arguments following the option as table names.

  • shell> mysql
    
    949

    Include triggers for each dumped table in the output. This option is enabled by default; disable it with

    shell> mysql
    
    950.

  • shell> mysql
    
    951',
    shell> mysql
    
    952'

    Dump only rows selected by the given

    shell> mysql
    
    409 condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

    Examples:

    shell> mysql
    
    41

Performance Options

The following options are the most relevant for the performance particularly of the restore operations. For large data sets, restore operation (processing the

shell> mysql
111 statements in the dump file) is the most time-consuming part. When it is urgent to restore data quickly, plan and test the performance of this stage in advance. For restore times measured in hours, you might prefer an alternative backup and restore solution, such as MySQL Enterprise Backup for
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42-only and mixed-use databases, or for
shell> mysql
004-only databases.

Performance is also affected by the , primarily for the dump operation.

  • shell> mysql
    
    957

    For those nontransactional tables that support the syntax, use that statement rather than regular statements.

    As of MySQL 5.6.6,

    shell> mysql
    
    960 inserts are deprecated, so this option will be removed in a future release.

  • shell> mysql
    
    961,
    shell> mysql
    
    962

    For each table, surround the statements with

    shell> mysql
    
    964 DISABLE KEYS */; and
    shell> mysql
    
    964 ENABLE KEYS */; statements. This makes loading the dump file faster because the indexes are created after all rows are inserted. This option is effective only for nonunique indexes of
    shell> mysql
    
    004 tables.

  • shell> mysql
    
    692,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    83

    Use multiple-row syntax that include several

    shell> mysql
    
    970 lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.

  • shell> mysql
    
    971

    Write statements rather than statements.

  • shell> mysql
    
    685

    This option, enabled by default, is shorthand for the combination of . It gives a fast dump operation and produces a dump file that can be reloaded into a MySQL server quickly.

    Because the

    shell> mysql
    
    685 option is enabled by default, you only specify its converse, the to turn off several default settings. See the discussion of for information about selectively enabling or disabling a subset of the options affected by
    shell> mysql
    
    685.

  • shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    65,
    shell> mysql
    
    134

    This option is useful for dumping large tables. It forces to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out.

  • shell> mysql
    
    690

    See the description for the option.

Transactional Options

The following options trade off the performance of the dump operation, against the reliability and consistency of the exported data.

  • shell> mysql
    
    815

    Surround each table dump with and statements. This results in faster inserts when the dump file is reloaded. See .

  • shell> mysql
    
    995,
    shell> mysql
    
    311

    Flush the MySQL server log files before starting the dump. This option requires the privilege. If you use this option in combination with the option, the logs are flushed for each database dumped. The exception is when using , , or : In this case, the logs are flushed only once, corresponding to the moment that all tables are locked. If you want your dump and the log flush to happen at exactly the same moment, you should use

    shell> mysql
    
    995 together with , , or .

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    006

    Send a statement to the server after dumping the

    shell> mysql --port=13306 --host=localhost
    
    33 database. This option should be used any time the dump contains the
    shell> mysql --port=13306 --host=localhost
    
    33 database and any other database that depends on the data in the
    shell> mysql --port=13306 --host=localhost
    
    33 database for proper restoration.

  • shell> mysql
    
    806,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    012

    Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off and .

  • shell> mysql
    
    805,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    016

    For each dumped database, lock all tables to be dumped before dumping them. The tables are locked with

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    017 to permit concurrent inserts in the case of
    shell> mysql
    
    004 tables. For transactional tables such as
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42, is a much better option than
    shell> mysql
    
    805 because it does not need to lock the tables at all.

    Because

    shell> mysql
    
    805 locks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states.

    Some options, such as , automatically enable

    shell> mysql
    
    805. If you want to override this, use
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    025 at the end of the option list.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    026

    Enclose the statements for each dumped table within

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    028 and statements.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    030

    Dump each table's rows sorted by its primary key, or by its first unique index, if such an index exists. This is useful when dumping a

    shell> mysql
    
    004 table to be loaded into an
    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42 table, but makes the dump operation take considerably longer.

  • shell> mysql
    
    676

    This option sends a SQL statement to the server before dumping data. It is useful only with transactional tables such as

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42, because then it dumps the consistent state of the database at the time when was issued without blocking any applications.

    When using this option, you should keep in mind that only

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    42 tables are dumped in a consistent state. For example, any
    shell> mysql
    
    004 or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    36 tables dumped while using this option may still change state.

    While a

    shell> mysql
    
    676 dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection can use the following statements: , , , , . Because a consistent read is not isolated from those statements, using them on a table being dumped can cause the underlying statement of to return incorrect contents or fail.

    The

    shell> mysql
    
    676 option and the option are mutually exclusive because causes any pending transactions to be committed implicitly.

    To dump large tables, combine the

    shell> mysql
    
    676 option with the .

Option Groups

  • The option turns on several settings that work together to perform a fast dump operation. All of these settings are on by default, because

    shell> mysql
    
    685 is on by default. Thus you rarely if ever specify
    shell> mysql
    
    685. Instead, you can turn these settings off as a group by specifying
    shell> mysql
    
    690, the optionally re-enable certain settings by specifying the associated options later on the command line.

  • The option turns off several settings that control whether optional statements and comments appear in the output. Again, you can follow this option with other options that re-enable certain settings, or turn all the settings on by using the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    057 form.

When you selectively enable or disable the effect of a group option, order is important because options are processed first to last. For example, would not have the intended effect; it is the same as by itself.

Examples

To make a backup of an entire database:

shell> mysql
42

To load the dump file back into the server:

shell> mysql
43

Another way to reload the dump file:

shell> mysql
44

is also very useful for populating databases by copying data from one MySQL server to another:

shell> mysql
45

You can dump several databases with one command:

shell> mysql
46

To dump all databases, use the option:

shell> mysql
47

For

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 tables, provides a way of making an online backup:

shell> mysql
48

This backup acquires a global read lock on all tables (using ) at the beginning of the dump. As soon as this lock has been acquired, the binary log coordinates are read and the lock is released. If long updating statements are running when the statement is issued, the MySQL server may get stalled until those statements finish. After that, the dump becomes lock free and does not disturb reads and writes on the tables. If the update statements that the MySQL server receives are short (in terms of execution time), the initial lock period should not be noticeable, even with many updates.

For point-in-time recovery (also known as “roll-forward,” when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see ) or at least know the binary log coordinates to which the dump corresponds:

shell> mysql
49

Or:

shell> mysql
50

The and options can be used simultaneously, which provides a convenient way to make an online backup suitable for use prior to point-in-time recovery if tables are stored using the

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 storage engine.

For more information on making backups, see , and .

Restrictions

does not dump the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
069 database by default. To dump
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
069, name it explicitly on the command line and also use the option.

never dumps the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
072 database.

Before MySQL 5.6.6, does not dump the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
073 or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
074 tables for dumps of the
shell> mysql --port=13306 --host=localhost
33 database. As of 5.6.6, the dump includes statements to recreate those tables so that they are not missing after reloading the dump file. Log table contents are not dumped.

It is not recommended to restore from a dump made using to a MySQL Server that has GTIDs enabled. See .

If you encounter problems backing up views due to insufficient privileges, see for a workaround.

4.5.5. mysqlimport — A Data Import Program

The client provides a command-line interface to the SQL statement. Most options to correspond directly to clauses of syntax. See .

Invoke like this:

shell> mysql
51

For each text file named on the command line, strips any extension from the file name and uses the result to determine the name of the table into which to import the file's contents. For example, files named

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
079,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
080, and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
081 all would be imported into a table named
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
081.

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
083 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.7. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
085 Options

Here is a sample session that demonstrates use of :

shell> mysql
52

4.5.6. mysqlshow — Display Database, Table, and Column Information

The client can be used to quickly see which databases exist, their tables, or a table's columns or indexes.

provides a command-line interface to several SQL statements. See . The same information can be obtained by using those statements directly. For example, you can issue them from the client program.

Invoke like this:

shell> mysql
53

  • If no database is given, a list of database names is shown.

  • If no table is given, all matching tables in the database are shown.

  • If no column is given, all matching columns and column types in the table are shown.

The output displays only the names of those databases, tables, or columns for which you have some privileges.

If the last argument contains shell or SQL wildcard characters (“

shell> mysql
384”, “
shell> mysql
383”, “
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
60”, or “
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
76”), only those names that are matched by the wildcard are shown. If a database name contains any underscores, those should be escaped with a backslash (some Unix shells require two) to get a list of the proper tables or columns. “
shell> mysql
384” and “
shell> mysql
383” characters are converted into SQL “
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
60” and “
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
76” wildcard characters. This might cause some confusion when you try to display the columns for a table with a “
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
76” in the name, because in this case, shows you only the table names that match the pattern. This is easily fixed by adding an extra “
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
60” last on the command line as a separate argument.

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
098 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.8. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
100 Options


4.5.7. mysqlslap — Load Emulation Client

is a diagnostic program designed to emulate client load for a MySQL server and to report the timing of each stage. It works as if multiple clients are accessing the server.

Invoke like this:

shell> mysql
54

Some options such as or enable you to specify a string containing an SQL statement or a file containing statements. If you specify a file, by default it must contain one statement per line. (That is, the implicit statement delimiter is the newline character.) Use the option to specify a different delimiter, which enables you to specify statements that span multiple lines or place multiple statements on a single line. You cannot include comments in a file; does not understand them.

runs in three stages:

  1. Create schema, table, and optionally any stored programs or data to use for the test. This stage uses a single client connection.

  2. Run the load test. This stage can use many client connections.

  3. Clean up (disconnect, drop table if specified). This stage uses a single client connection.

Examples:

Supply your own create and query SQL statements, with 50 clients querying and 200 selects for each (enter the command on a single line):

shell> mysql
55

Let build the query SQL statement with a table of two columns and three columns. Use five clients querying 20 times each. Do not create the table or insert the data (that is, use the previous test's schema and data):

shell> mysql
56

Tell the program to load the create, insert, and query SQL statements from the specified files, where the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
106 file has multiple table creation statements delimited by
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
107 and multiple insert statements delimited by
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
107. The
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
102 file will have multiple queries delimited by
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
107. Run all the load statements, then run all the queries in the query file with five clients (five times each):

shell> mysql
57

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
111 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.9. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
113 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql
    
    587

    Generate SQL statements automatically when they are not supplied in files or using command options.

  • Add an

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 column to automatically generated tables.

  • Specify how many queries to generate automatically.

  • Add a GUID-based primary key to automatically generated tables.

  • Specify the test load type. The permissible values are

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    123 (scan tables),
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    124 (insert into tables),
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    125 (read primary keys),
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    126 (update primary keys), or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    127 (half inserts, half scanning selects). The default is
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    127.

  • Specify how many secondary indexes to add to automatically generated tables. By default, none are added.

  • How many different queries to generate for automatic tests. For example, if you run a

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    125 test that performs 1000 selects, you can use this option with a value of 1000 to run 1000 unique queries, or with a value of 50 to perform 50 different selects. The default is 10.

  • How many different queries to generate for . The default is 10.

  • How many row inserts to perform on each thread. The default is 100.

  • How many statements to execute before committing. The default is 0 (no commits are done).

  • ,

    shell> mysql
    
    041

    Compress all information sent between the client and the server if both support compression.

  • , -c

    shell> mysql --port=13306 --host=localhost
    
    41

    The number of clients to simulate when issuing the statement.

  • The file or string containing the statement to use for creating the table.

  • The schema in which to run the tests. drops the schema at the end of the test run. This option was added in MySQL 5.6.3.

  • The schema in which to run the tests.

  • Generate output in comma-separated values format. The output goes to the named file, or to the standard output if no file is given.

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    149.

  • Print some debugging information when the program exits.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    21

    Print debugging information and memory and CPU usage statistics when the program exits.

  • The client-side authentication plugin to use. See .

    This option was added in MySQL 5.6.2.

  • , -F

    shell> mysql --host=remote.example.com
    
    42

    The delimiter to use in SQL statements supplied in files or using command options.

  • Detach (close and reopen) each connection after each

    shell> mysql --port=13306 --host=localhost
    
    41 statements. The default is 0 (connections are not detached).

  • Enable the

    shell> mysql
    
    063 cleartext authentication plugin. (See .) This option was added in MySQL 5.6.7.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    161

    The storage engine to use for creating tables.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Connect to the MySQL server on the given host.

  • , -i

    shell> mysql --port=13306 --host=localhost
    
    41

    The number of times to run the tests.

  • , -x

    shell> mysql --port=13306 --host=localhost
    
    41

    The number of columns to use if is specified.

  • , -y

    shell> mysql --port=13306 --host=localhost
    
    41

    The number of columns to use if is specified.

  • Limit each client to approximately this many queries. Query counting takes into account the statement delimiter. For example, if you invoke as follows, the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74 delimiter is recognized so that each instance of the query string counts as two queries. As a result, 5 rows (not 10) are inserted.

    shell> mysql
    
    58
  • Do not connect to databases. only prints what it would have done.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    24

    On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for the connection.

  • The file or string containing the statement to execute after the tests have completed. This execution is not counted for timing purposes.

  • On Windows, the shared-memory name to use, for connections made using shared memory to a local server. This option applies only if the server supports shared-memory connections.

  • The string to execute using

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    192 after the tests have completed. This execution is not counted for timing purposes.

  • The file or string containing the statement to execute before running the tests. This execution is not counted for timing purposes.

  • The string to execute using

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    192 before running the tests. This execution is not counted for timing purposes.

  • The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • , -q

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81

    The file or string containing the statement to use for retrieving data.

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. No output.

  • ,

    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    45

    Options that begin with specify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does. This option can be used multiple times to increase the amount of information.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

4.6. MySQL Administrative and Utility Programs

This section describes administrative programs and programs that perform miscellaneous utility operations.

4.6.1. innochecksum — Offline InnoDB File Checksum Utility

prints checksums for

shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 files. This tool reads an
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 tablespace file, calculates the checksum for each page, compares the calculated checksum to the stored checksum, and reports mismatches, which indicate damaged pages. It was originally developed to speed up verifying the integrity of tablespace files after power outages but can also be used after file copies. Because checksum mismatches will cause
shell> mysql --port=13306 --host=127.0.0.1
shell> mysql --port=13306 --protocol=TCP
42 to deliberately shut down a running server, it can be preferable to use this tool rather than waiting for a server in production usage to encounter the damaged pages.

cannot be used on tablespace files that the server already has open. For such files, you should use to check tables within the tablespace.

If checksum mismatches are found, you would normally restore the tablespace from backup or start the server and attempt to use to make a backup of the tables within the tablespace.

Invoke like this:

shell> mysql
59

supports the following options. For options that refer to page numbers, the numbers are zero-based.

  • shell> mysql
    
    039

    Print a count of the number of pages in the file.

  • shell> mysql
    
    933

    Debug mode; prints checksums for each page.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    219

    End at this page number.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    220

    Check only this page number.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    221

    Start at this page number.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode; print a progress indicator every five seconds.

4.6.2. myisam_ftdump — Display Full-Text Index information

displays information about

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
223 indexes in
shell> mysql
004 tables. It reads the
shell> mysql
004 index file directly, so it must be run on the server host where the table is located. Before using , be sure to issue a
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
226 statement first if the server is running.

scans and dumps the entire index, which is not particularly fast. On the other hand, the distribution of words changes infrequently, so it need not be run often.

Invoke like this:

shell> mysql
60

The

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
227 argument should be the name of a
shell> mysql
004 table. You can also specify a table by naming its index file (the file with the
shell> mysql
659 suffix). If you do not invoke in the directory where the table files are located, the table or index file name must be preceded by the path name to the table's database directory. Index numbers begin with 0.

Example: Suppose that the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
65 database contains a table named
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
231 that has the following definition:

shell> mysql
61

The index on

shell> mysql
438 is index 0 and the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
223 index on
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
234 is index 1. If your working directory is the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
65 database directory, invoke as follows:

shell> mysql
62

If the path name to the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
65 database directory is
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
237, you can also specify the table name argument using that path name. This is useful if you do not invoke in the database directory:

shell> mysql
63

You can use to generate a list of index entries in order of frequency of occurrence like this:

shell> mysql
64

supports the following options:

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    67
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql
    
    039

    Calculate per-word statistics (counts and global weights).

  • ,

    shell> mysql
    
    933

    Dump the index, including data offsets and word weights.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    016

    Report the length distribution.

  • ,

    shell> mysql --host=localhost
    
    95

    Report global index statistics. This is the default operation if no other operation is specified.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more output about what the program does.

4.6.3. myisamchk — MyISAM Table-Maintenance Utility

The utility gets information about your database tables or checks, repairs, or optimizes them. works with

shell> mysql
004 tables (tables that have
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
252 and
shell> mysql
659 files for storing data and indexes).

You can also use the and statements to check and repair

shell> mysql
004 tables. See , and .

The use of with partitioned tables is not supported.

It is best to make a backup of a table before performing a table repair operation; under some circumstances the operation might cause data loss. Possible causes include but are not limited to file system errors.

Invoke like this:

shell> mysql
65

The

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
259 specify what you want to do. They are described in the following sections. You can also get a list of options by invoking .

With no options, simply checks your table as the default operation. To get more information or to tell to take corrective action, specify options as described in the following discussion.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
227 is the database table you want to check or repair. If you run somewhere other than in the database directory, you must specify the path to the database directory, because has no idea where the database is located. In fact, does not actually care whether the files you are working on are located in a database directory. You can copy the files that correspond to a database table into some other location and perform recovery operations on them there.

You can name several tables on the command line if you wish. You can also specify a table by naming its index file (the file with the

shell> mysql
659 suffix). This enables you to specify all tables in a directory by using the pattern
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
262. For example, if you are in a database directory, you can check all the
shell> mysql
004 tables in that directory like this:

shell> mysql
66

If you are not in the database directory, you can check all the tables there by specifying the path to the directory:

shell> mysql
67

You can even check all tables in all databases by specifying a wildcard with the path to the MySQL data directory:

shell> mysql
68

The recommended way to quickly check all

shell> mysql
004 tables is:

shell> mysql
69

If you want to check all

shell> mysql
004 tables and repair any that are corrupted, you can use the following command:

shell> mysql
70

This command assumes that you have more than 64MB free. For more information about memory allocation with , see .

For additional information about using , see .

You must ensure that no other program is using the tables while you are running . The most effective means of doing so is to shut down the MySQL server while running , or to lock all tables that is being used on.

Otherwise, when you run , it may display the following error message:

shell> mysql
71

This means that you are trying to check a table that has been updated by another program (such as the server) that hasn't yet closed the file or that has died without closing the file properly, which can sometimes lead to the corruption of one or more

shell> mysql
004 tables.

If is running, you must force it to flush any table modifications that are still buffered in memory by using . You should then ensure that no one is using the tables while you are running

However, the easiest way to avoid this problem is to use instead of to check tables. See .

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
271 group of an option file. also supports the options for processing option files described at .

Table 4.10. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
272 Options

FormatOption FileDescriptionIntroducedDeprecatedAnalyze the distribution of key valuesMake a backup of the .MYD file as file_name-time.BAKFind the record that a block at the given offset belongs toCheck the table for errorsCheck only tables that have changed since the last checkCorrect the checksum information for the tableMaximum length of the data file (when re-creating data file when it is full)Write a debugging logdecode_bits=#decode_bitsDecode_bitsPrint some descriptive information about the tableDo very thorough table check or repair that tries to recover every possible row from the data fileCheck only tables that haven't been closed properlyDo a repair operation automatically if myisamchk finds any errors in the table--forceforce-recoverOverwrite old temporary files. For use with the -r or -o optionft_max_word_len=#ft_max_word_lenMaximum word length for FULLTEXT indexesft_min_word_len=#ft_min_word_lenMinimum word length for FULLTEXT indexesft_stopword_file=valueft_stopword_fileUse stopwords from this file instead of built-in listDisplay help message and exitDisplay help message and exitPrint informational statistics about the table that is checkedkey_buffer_size=#key_buffer_sizeThe size of the buffer used for index blocks for MyISAM tablesA bit-value that indicates which indexes to updateSkip rows larger than the given length if myisamchk cannot allocate memory to hold themDo a check that is faster than an --extend-check operationmyisam_block_size=#myisam_block_sizeBlock size to be used for MyISAM index pagesmyisam_sort_buffer_size=#myisam_sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE5.6.9Uses the same technique as -r and -n, but creates all the keys in parallel, using different threads (beta)Achieve a faster repair by not modifying the data file.read_buffer_size=#read_buffer_sizeEach thread that does a sequential scan allocates a buffer of this size for each table it scansDon't mark the table as checkedDo a repair that can fix almost any problem except unique keys that aren't uniqueDo a repair using an old recovery method that reads through all rows in order and updates all index trees based on the rows foundForce AUTO_INCREMENT numbering for new records to start at the given valueSpecify the collation to use for sorting table indexesSilent modesort_buffer_size=#sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE5.6.9Sort the index tree blocks in high-low ordersort_key_blocks=#sort_key_blockssort_key_blocksSort records according to a particular indexForce myisamchk to use sorting to resolve the keys even if the temporary files would be very largestats_method=valuestats_methodSpecifies how MyISAM index statistics collection code should treat NULLsPath of the directory to be used for storing temporary filesUnpack a table that was packed with myisampackStore information in the .MYI file to indicate when the table was checked and whether the table crashedVerbose modeDisplay version information and exitwrite_buffer_size=#write_buffer_sizeWrite buffer size


4.6.3.1. myisamchk General Options

The options described in this section can be used for any type of table maintenance operation performed by . The sections following this one describe options that pertain only to specific operations, such as table checking or repairing.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit. Options are grouped by type of operation.

  • ,

    shell> mysql
    
    073

    Display a help message and exit. Options are presented in a single list.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    16

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    281.

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. Write output only when errors occur. You can use

    shell> mysql --host=localhost
    
    95 twice (
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    285) to make very silent.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does. This can be used with

    shell> mysql
    
    933 and
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    83. Use
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60 multiple times (
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    291,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    292) for even more output.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • ,

    shell> mysql
    
    191

    Instead of terminating with an error if the table is locked, wait until the table is unlocked before continuing. If you are running with external locking disabled, the table can be locked only by another command.

You can also set the following variables by using

shell> mysql
196=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81 syntax:

VariableDefault Value

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
2999
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
300version-dependent
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
3014
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
302built-in list
shell> mysql --host=remote.example.com
14523264
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
3041024
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
30516
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
306262136
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
3072097144
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
30816
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
309nulls_unequal
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
310262136

The possible variables and their default values can be examined with :

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
307 is used when the keys are repaired by sorting keys, which is the normal case when you use . As of MySQL 5.6.9,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
313 is available as an alternative name to
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
307.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
313 is preferable to
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
307 because its name corresponds to the server system variable that has a similar meaning.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
307 should be considered deprecated.

shell> mysql --host=remote.example.com
14 is used when you are checking the table with or when the keys are repaired by inserting keys row by row into the table (like when doing normal inserts). Repairing through the key buffer is used in the following cases:

  • You use .

  • The temporary files needed to sort the keys would be more than twice as big as when creating the key file directly. This is often the case when you have large key values for , , or columns, because the sort operation needs to store the complete key values as it proceeds. If you have lots of temporary space and you can force to repair by sorting, you can use the option.

Repairing through the key buffer takes much less disk space than using sorting, but is also much slower.

If you want a faster repair, set the

shell> mysql --host=remote.example.com
14 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
313 variables to about 25% of your available memory. You can set both variables to large values, because only one of them is used at a time.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
304 is the size used for index blocks.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
309 influences how
shell> mysql
906 values are treated for index statistics collection when the option is given. It acts like the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
332 system variable. For more information, see the description of
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
332 in , and .

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
301 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
300 indicate the minimum and maximum word length for
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
223 indexes on
shell> mysql
004 tables.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
302 names the stopword file. These need to be set under the following circumstances.

If you use to perform an operation that modifies table indexes (such as repair or analyze), the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
223 indexes are rebuilt using the default full-text parameter values for minimum and maximum word length and the stopword file unless you specify otherwise. This can result in queries failing.

The problem occurs because these parameters are known only by the server. They are not stored in

shell> mysql
004 index files. To avoid the problem if you have modified the minimum or maximum word length or the stopword file in the server, specify the same
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
301,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
300, and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
302 values to that you use for . For example, if you have set the minimum word length to 3, you can repair a table with like this:

shell> mysql
72

To ensure that and the server use the same values for full-text parameters, you can place each one in both the

shell> mysql --host=remote.example.com
07 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
271 sections of an option file:

shell> mysql
73

An alternative to using is to use the , , , or . These statements are performed by the server, which knows the proper full-text parameter values to use.

4.6.3.2. myisamchk Check Options

supports the following options for table checking operations:

  • ,

    shell> mysql
    
    039

    Check the table for errors. This is the default operation if you specify no option that selects an operation type explicitly.

  • ,

    shell> mysql
    
    041

    Check only tables that have changed since the last check.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    83

    Check the table very thoroughly. This is quite slow if the table has many indexes. This option should only be used in extreme cases. Normally, or should be able to determine whether there are any errors in the table.

    If you are using and have plenty of memory, setting the

    shell> mysql --host=remote.example.com
    
    14 variable to a large value helps the repair operation run faster.

    See also the description of this option under table repair options.

    For a description of the output format, see .

  • ,

    shell> mysql
    
    311

    Check only tables that haven't been closed properly.

  • ,

    shell> mysql
    
    068

    Do a repair operation automatically if finds any errors in the table. The repair type is the same as that specified with the or

    shell> mysql
    
    136 option.

  • ,

    shell> mysql
    
    075

    Print informational statistics about the table that is checked.

  • ,

    shell> mysql
    
    037

    Do a check that is faster than an operation. This finds only 99.99% of all errors, which should be good enough in most cases.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    21

    Do not mark the table as checked. This is useful if you use to check a table that is in use by some other application that does not use locking, such as when run with external locking disabled.

  • ,

    shell> mysql
    
    149

    Store information in the

    shell> mysql
    
    659 file to indicate when the table was checked and whether the table crashed. This should be used to get full benefit of the option, but you shouldn't use this option if the server is using the table and you are running it with external locking disabled.

4.6.3.3. myisamchk Repair Options

supports the following options for table repair operations (operations performed when an option such as or is given):

  • ,

    shell> mysql
    
    022

    Make a backup of the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    252 file as
    shell> mysql --host=remote.example.com
    
    38-
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    383.BAK

  • The directory where character sets are installed. See .

  • Correct the checksum information for the table.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    387

    The maximum length of the data file (when re-creating data file when it is “full”).

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    83

    Do a repair that tries to recover every possible row from the data file. Normally, this also finds a lot of garbage rows. Do not use this option unless you are desperate.

    See also the description of this option under table checking options.

    For a description of the output format, see .

  • ,

    shell> mysql
    
    068

    Overwrite old intermediate files (files with names like

    shell> mysql
    
    889.TMD) instead of aborting.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    394

    For , the option value is a bit-value that indicates which indexes to update. Each binary bit of the option value corresponds to a table index, where the first index is bit 0. An option value of 0 disables updates to all indexes, which can be used to get faster inserts. Deactivated indexes can be reactivated by using .

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    016

    Do not follow symbolic links. Normally repairs the table that a symlink points to. This option does not exist as of MySQL 4.0 because versions from 4.0 on do not remove symlinks during repair operations.

  • Skip rows larger than the given length if cannot allocate memory to hold them.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71

    Use the same technique as

    shell> mysql
    
    136 and
    shell> mysql
    
    179, but create all the keys in parallel, using different threads. This is beta-quality code. Use at your own risk!

  • ,

    shell> mysql
    
    134

    Achieve a faster repair by modifying only the index file, not the data file. You can specify this option twice to force to modify the original data file in case of duplicate keys.

  • ,

    shell> mysql
    
    136

    Do a repair that can fix almost any problem except unique keys that are not unique (which is an extremely unlikely error with

    shell> mysql
    
    004 tables). If you want to recover a table, this is the option to try first. You should try only if reports that the table cannot be recovered using . (In the unlikely case that fails, the data file remains intact.)

    If you have lots of memory, you should increase the value of

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    313.

  • ,

    shell> mysql
    
    100

    Do a repair using an old recovery method that reads through all rows in order and updates all index trees based on the rows found. This is an order of magnitude slower than , but can handle a couple of very unlikely cases that cannot. This recovery method also uses much less disk space than . Normally, you should repair first using , and then with only if fails.

    If you have lots of memory, you should increase the value of

    shell> mysql --host=remote.example.com
    
    14.

  • Change the character set used by the table indexes. This option was replaced by in MySQL 5.0.3.

  • Specify the collation to use for sorting table indexes. The character set name is implied by the first part of the collation name.

  • ,

    shell> mysql
    
    179

    Force to use sorting to resolve the keys even if the temporary files would be very large.

  • ,

    shell> mysql --host=localhost
    
    93

    The path of the directory to be used for storing temporary files. If this is not set, uses the value of the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    56 environment variable. can be set to a list of directory paths that are used successively in round-robin fashion for creating temporary files. The separator character between directory names is the colon (“
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    429”) on Unix and the semicolon (“
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    74”) on Windows.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    69

    Unpack a table that was packed with .

4.6.3.4. Other myisamchk Options

supports the following options for actions other than table checks and repairs:

  • ,

    shell> mysql
    
    587

    Analyze the distribution of key values. This improves join performance by enabling the join optimizer to better choose the order in which to join the tables and which indexes it should use. To obtain information about the key distribution, use a command or the SHOW INDEX FROM

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    227 statement.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    438

    Find the record that a block at the given offset belongs to.

  • ,

    shell> mysql
    
    933

    Print some descriptive information about the table. Specifying the option once or twice produces additional information. See .

  • , -A[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81]

    Force

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 numbering for new records to start at the given value (or higher, if there are existing records with
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 values this large). If
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    81 is not specified,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 numbers for new records begin with the largest value currently in the table, plus one.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    75

    Sort the index tree blocks in high-low order. This optimizes seeks and makes table scans that use indexes faster.

  • , -R

    shell> mysql --port=13306 --host=localhost
    
    41

    Sort records according to a particular index. This makes your data much more localized and may speed up range-based and

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    453 operations that use this index. (The first time you use this option to sort a table, it may be very slow.) To determine a table's index numbers, use , which displays a table's indexes in the same order that sees them. Indexes are numbered beginning with 1.

    If keys are not packed (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    455), they have the same length, so when sorts and moves records, it just overwrites record offsets in the index. If keys are packed (
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    456), must unpack key blocks first, then re-create indexes and pack the key blocks again. (In this case, re-creating indexes is faster than updating offsets for each index.)

4.6.3.5. Obtaining Table Information with myisamchk

To obtain a description of a

shell> mysql
004 table or statistics about it, use the commands shown here. The output from these commands is explained later in this section.

  • Runs in “describe mode” to produce a description of your table. If you start the MySQL server with external locking disabled, may report an error for a table that is updated while it runs. However, because does not change the table in describe mode, there is no risk of destroying data.

  • Adding

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60 runs in verbose mode so that it produces more information about the table. Adding
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60 a second time produces even more information.

  • Shows only the most important information from a table. This operation is slow because it must read the entire table.

  • This is like

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    464, but tells you what is being done.

The

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
227 argument can be either the name of a
shell> mysql
004 table or the name of its index file, as described in . Multiple
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
227 arguments can be given.

Suppose that a table named

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
468 has the following structure. (The
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
469 table option is included so that in the example output from shown later, some values are smaller and fit the output format more easily.)

shell> mysql
74

Suppose also that the table has these data and index file sizes:

shell> mysql
75

Example of output:

shell> mysql
76

Explanations for the types of information produces are given here. “Keyfile” refers to the index file. “Record” and “row” are synonymous, as are “field” and “column.”

The initial part of the table description contains these values:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    470

    Name of the

    shell> mysql
    
    004 (index) file.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    472

    The format used to store table rows. The preceding examples use

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    473. Other possible values are
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    474 and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    475. (
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    475 corresponds to what
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    477 reports as
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    478.)

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    479

    The table default character set.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    480

    Version of

    shell> mysql
    
    004 format. Currently always 1.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    482

    When the data file was created.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    483

    When the index/data file was last reconstructed.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    484

    Table status flags. Possible values are

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    485,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    486,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    487,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    488,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    489, and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    490.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    491,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    492

    The key number associated the table's

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 column, and the most recently generated value for this column. These fields do not appear if there is no such column.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    494

    The number of rows in the table.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    495

    How many deleted blocks still have reserved space. You can optimize your table to minimize this space. See .

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    497

    For dynamic-row format, this indicates how many data blocks there are. For an optimized table without fragmented rows, this is the same as

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    494.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    499

    How many bytes of unreclaimed deleted data there are. You can optimize your table to minimize this space. See .

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    501

    The size of the data file pointer, in bytes. It is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes, but this cannot be controlled from MySQL yet. For fixed tables, this is a row address. For dynamic tables, this is a byte address.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    502

    The size of the index file pointer, in bytes. It is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but this is calculated automatically by MySQL. It is always a block address.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    503

    How long the table data file can become, in bytes.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    504

    How long the table index file can become, in bytes.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    505

    How much space each row takes, in bytes.

The

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
506 part of the output includes a list of all keys in the table. For each key, displays some low-level information:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    507

    This key's number. This value is shown only for the first column of the key. If this value is missing, the line corresponds to the second or later column of a multiple-column key. For the table shown in the example, there are two

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    506 lines for the second index. This indicates that it is a multiple-part index with two parts.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    509

    Where in the row this portion of the index starts.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    510

    How long this portion of the index is. For packed numbers, this should always be the full length of the column. For strings, it may be shorter than the full length of the indexed column, because you can index a prefix of a string column. The total length of a multiple-part key is the sum of the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    510 values for all key parts.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    512

    Whether a key value can exist multiple times in the index. Possible values are

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    513 or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    514 (multiple).

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    515

    What data type this portion of the index has. This is a

    shell> mysql
    
    004 data type with the possible values
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    517,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    518, or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    519.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    520

    Address of the root index block.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    521

    The size of each index block. By default this is 1024, but the value may be changed at compile time when MySQL is built from source.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    522

    This is a statistical value used by the optimizer. It tells how many rows there are per value for this index. A unique index always has a value of 1. This may be updated after a table is loaded (or greatly changed) with . If this is not updated at all, a default value of 30 is given.

The last part of the output provides information about each column:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    523

    The column number.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    509

    The byte position of the column within table rows.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    525

    The length of the column in bytes.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    526,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    527

    For columns that can be

    shell> mysql
    
    906,
    shell> mysql
    
    004 stores
    shell> mysql
    
    906 values as a flag in a byte. Depending on how many nullable columns there are, there can be one or more bytes used for this purpose. The
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    526 and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    527 values, if nonempty, indicate which byte and bit contains that flag indicating whether the column is
    shell> mysql
    
    906.

    The position and number of bytes used to store

    shell> mysql
    
    906 flags is shown in the line for field 1. This is why there are six
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    523 lines for the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    468 table even though it has only five columns.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    515

    The data type. The value may contain any of the following descriptors:

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      538

      All rows have the same value.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      539

      Do not store endspace.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      540

      Do not store endspace and do not do endspace compression for all values.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      541

      Do not store endspace. Do not store empty values.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      542

      The column was converted to an .

    • zerofill(

      shell> mysql --port=13306 --host=localhost
      
      41)

      The most significant

      shell> mysql --port=13306 --host=localhost
      
      41 bytes in the value are always 0 and are not stored.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      546

      Do not store zeros.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      547

      Zero values are stored using one bit.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    548

    The number of the Huffman tree associated with the column.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    549

    The number of bits used in the Huffman tree.

The

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
548 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
549 fields are displayed if the table has been compressed with . See , for an example of this information.

Example of output:

shell> mysql
77

output includes the following information:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    494

    The number of rows in the table.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    495

    How many deleted blocks still have reserved space. You can optimize your table to minimize this space. See .

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    507

    The key number.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    556

    What percentage of the keyblocks are used. When a table has just been reorganized with , the values are very high (very near theoretical maximum).

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    475

    MySQL tries to pack key values that have a common suffix. This can only be used for indexes on and columns. For long indexed strings that have similar leftmost parts, this can significantly reduce the space used. In the preceding example, the second key is 40 bytes long and a 97% reduction in space is achieved.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    560

    How deep the B-tree for this key is. Large tables with long key values get high values.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    561

    How many rows are in the table.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    562

    The average row length. This is the exact row length for tables with fixed-length rows, because all rows have the same length.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    475

    MySQL strips spaces from the end of strings. The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    475 value indicates the percentage of savings achieved by doing this.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    565

    What percentage of the data file is used.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    566

    What percentage of the data file is unused.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    567

    Average number of blocks per row (that is, how many links a fragmented row is composed of). This is always 1.0 for fixed-format tables. This value should stay as close to 1.0 as possible. If it gets too large, you can reorganize the table. See .

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    569

    How many blocks (links) are used. For fixed-format tables, this is the same as the number of rows.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    570

    How many blocks (links) are deleted.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    571

    How many bytes in the data file are used.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    499

    How many bytes in the data file are deleted (unused).

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    573

    If a row is updated to a shorter length, some space is lost. This is the sum of all such losses, in bytes.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    574

    When the dynamic table format is used, row fragments are linked with pointers (4 to 7 bytes each).

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    574 is the sum of the amount of storage used by all such pointers.

4.6.3.6. myisamchk Memory Usage

Memory allocation is important when you run . uses no more memory than its memory-related variables are set to. If you are going to use on very large tables, you should first decide how much memory you want it to use. The default is to use only about 3MB to perform repairs. By using larger values, you can get to operate faster. For example, if you have more than 512MB RAM available, you could use options such as these (in addition to any other options you might specify):

shell> mysql
78

Using

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
576 is probably enough for most cases.

Be aware that uses temporary files in

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56. If
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
56 points to a memory file system, out of memory errors can easily occur. If this happens, run with the option to specify a directory located on a file system that has more space.

When performing repair operations, also needs a lot of disk space:

  • Twice the size of the data file (the original file and a copy). This space is not needed if you do a repair with ; in this case, only the index file is re-created. This space must be available on the same file system as the original data file, as the copy is created in the same directory as the original.

  • Space for the new index file that replaces the old one. The old index file is truncated at the start of the repair operation, so you usually ignore this space. This space must be available on the same file system as the original data file.

  • When using or (but not when using ), you need space on disk for sorting. This space is allocated in the temporary directory (specified by

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    56 or ). The following formula yields the amount of space required:

    shell> mysql
    
    79

    You can check the length of the keys and the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    586 with (see ). The
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    586 and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    589 values are the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    501 and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    494 values in the table description. To determine the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    592 value, check the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    507 lines in the table description. The
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    510 column indicates the number of bytes for each key part. For a multiple-column index, the key size is the sum of the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    510 values for all key parts.

If you have a problem with disk space during repair, you can try instead of .

4.6.4. myisamlog — Display MyISAM Log File Contents

processes the contents of a

shell> mysql
004 log file.

Invoke like this:

shell> mysql
80

The default operation is update (

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
69). If a recovery is done (
shell> mysql
136), all writes and possibly updates and deletes are done and errors are only counted. The default log file name is
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
601 for and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
602 for isamlog if no
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
603 argument is given. If tables are named on the command line, only those tables are updated.

supports the following options:

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    605

    Display a help message and exit.

  • -c

    shell> mysql --port=13306 --host=localhost
    
    41

    Execute only

    shell> mysql --port=13306 --host=localhost
    
    41 commands.

  • -f

    shell> mysql --port=13306 --host=localhost
    
    41

    Specify the maximum number of open files.

  • shell> mysql
    
    075

    Display extra information before exiting.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    610

    Specify the starting offset.

  • -p

    shell> mysql --port=13306 --host=localhost
    
    41

    Remove

    shell> mysql --port=13306 --host=localhost
    
    41 components from path.

  • shell> mysql
    
    136

    Perform a recovery operation.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    614

    Specify record position file and record position.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    69

    Perform an update operation.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more output about what the program does. This option can be given multiple times to produce more and more output.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    617

    Specify the write file.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information.

4.6.5. myisampack — Generate Compressed, Read-Only MyISAM Tables

The utility compresses

shell> mysql
004 tables. works by compressing each column in the table separately. Usually, packs the data file 40% to 70%.

When the table is used later, the server reads into memory the information needed to decompress columns. This results in much better performance when accessing individual rows, because you only have to uncompress exactly one row.

MySQL uses

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
620 when possible to perform memory mapping on compressed tables. If
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
620 does not work, MySQL falls back to normal read/write file operations.

Please note the following:

  • If the server was invoked with external locking disabled, it is not a good idea to invoke if the table might be updated by the server during the packing process. It is safest to compress tables with the server stopped.

  • After packing a table, it becomes read only. This is generally intended (such as when accessing packed tables on a CD).

Invoke like this:

shell> mysql
81

Each file name argument should be the name of an index (

shell> mysql
659) file. If you are not in the database directory, you should specify the path name to the file. It is permissible to omit the
shell> mysql
659 extension.

After you compress a table with , you should use to rebuild its indexes. .

supports the following options. It also reads option files and supports the options for processing them described at .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql
    
    098

    Make a backup of each table's data file using the name

    shell> mysql
    
    889.OLD.

  • The directory where character sets are installed. See .

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql
    
    608.

  • ,

    shell> mysql
    
    068

    Produce a packed table even if it becomes larger than the original or if the intermediate file from an earlier invocation of exists. ( creates an intermediate file named

    shell> mysql
    
    889.TMD in the database directory while it compresses the table. If you kill , the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    638 file might not be deleted.) Normally, exits with an error if it finds that
    shell> mysql
    
    889.TMD exists. With , packs the table anyway.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    642

    Join all tables named on the command line into a single packed table

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    643. All tables that are to be combined must have identical structure (same column names and types, same indexes, and so forth).

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    643 must not exist prior to the join operation. All source tables named on the command line to be merged into
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    643 must exist. The source tables are read for the join operation but not modified. The join operation does not create a
    shell> mysql
    
    658 file for
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    643, so after the join operation finishes, copy the
    shell> mysql
    
    658 file from one of the source tables and name it
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    643.frm
    .

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. Write output only when errors occur.

  • ,

    shell> mysql
    
    176

    Do not actually pack the table, just test packing it.

  • ,

    shell> mysql
    
    888

    Use the named directory as the location where creates temporary files.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Write information about the progress of the packing operation and its result.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • ,

    shell> mysql
    
    191

    Wait and retry if the table is in use. If the server was invoked with external locking disabled, it is not a good idea to invoke if the table might be updated by the server during the packing process.

The following sequence of commands illustrates a typical table compression session:

shell> mysql
82

displays the following kinds of information:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    662

    The number of columns for which no extra packing is used.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    663

    The number of columns containing values that are only spaces. These occupy one bit.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    664

    The number of columns containing values that are only binary zeros. These occupy one bit.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    665

    The number of integer columns that do not occupy the full byte range of their type. These are changed to a smaller type. For example, a column (eight bytes) can be stored as a column (one byte) if all its values are in the range from

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    668 to
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    669.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    670

    The number of decimal columns that are stored with leading spaces. In this case, each value contains a count for the number of leading spaces.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    671

    The number of columns that have a lot of trailing spaces. In this case, each value contains a count for the number of trailing spaces.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    542

    The column had only a small number of different values, which were converted to an before Huffman compression.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    674

    The number of columns for which all values are zero.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    675

    The initial number of Huffman trees.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    676

    The number of distinct Huffman trees left after joining trees to save some header space.

After a table has been compressed, the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
523 lines displayed by include additional information about each column:

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    515

    The data type. The value may contain any of the following descriptors:

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      538

      All rows have the same value.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      539

      Do not store endspace.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      540

      Do not store endspace and do not do endspace compression for all values.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      541

      Do not store endspace. Do not store empty values.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      542

      The column was converted to an .

    • zerofill(

      shell> mysql --port=13306 --host=localhost
      
      41)

      The most significant

      shell> mysql --port=13306 --host=localhost
      
      41 bytes in the value are always 0 and are not stored.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      546

      Do not store zeros.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      547

      Zero values are stored using one bit.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    548

    The number of the Huffman tree associated with the column.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    549

    The number of bits used in the Huffman tree.

After you run , you must run to re-create any indexes. At this time, you can also sort the index blocks and create statistics needed for the MySQL optimizer to work more efficiently:

shell> mysql
83

After you have installed the packed table into the MySQL database directory, you should execute to force to start using the new table.

To unpack a packed table, use the option to .

4.6.6. mysql_config_editor — MySQL Configuration Utility

The utility (available as of MySQL 5.6.6) enables you to store authentication credentials in an encrypted login file named

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03. The file location is the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
693 directory on Windows and the current user's home directory on non-Windows systems. The file can be read later by MySQL client programs to obtain authentication credentials for connecting to MySQL Server.

To specify an alternate file name, set the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
694 environment variable. This variable is used by the mysql-test-run.pl testing utility, but also is recognized by
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
695 and by MySQL clients such as , , and so forth.

encrypts the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file so it cannot be read as clear text, and its contents when decrypted by client programs are used only in memory. In this way, passwords can be stored in a file in non-cleartext format and used later without ever needing to be exposed on the command line or in an environment variable. provides a
shell> mysql
273 command that enables the user to display the file contents, but even in this case, password values are masked so as never to appear in a way that other users can see them.

The encryption used by prevents passwords from appearing in

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 as clear text and provides a measure of security by preventing inadvertent password exposure. For example, if you display a regular unencrypted
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
41 option file on the screen, any passwords it contains are visible for anyone to see. With
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03, that is not true. But the encryption used will not deter a determined attacker and you should not consider it unbreakable. A user who can gain system administration privileges on your machine to access your files could decrypt the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file with some effort.

The login file must be readable and writable to the current user, and inaccessible to other users. Otherwise, ignores it, and the file is not used by client programs, either. On Windows, this constraint does not apply; instead, the user must have access to the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
693 directory.

The unencrypted format of the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 login file consists of option groups, similar to other option files. Each option group in
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 is called a “login path,” which is a group that permits only a limited set of options:
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
04,
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
05, and
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
06. Think of a login path as a set of values that indicate the server host and the credentials for authenticating with the server. Here is an example:

shell> mysql
84

When you invoke a client program to connect to the server,

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 is used in conjunction with other option files. Its precedence is higher than other option files, but less than options specified explicitly on the client command line. For information about the order in which option files are used, see .

Invoke

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
695 like this:

shell> mysql
85

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
710 consists of general options.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
711 indicates what command to perform, and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
712 indicates any additional options needed by the command.

The command indicates what action to perform on the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 login file. For example,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
714 writes a login path to the file,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
715 removes a login path, and
shell> mysql
273 displays login path contents. Any options given provide information to the command, such as the login path name and the values to use in the login path.

The position of the command name within the set of program arguments is significant. For example, these command lines have the same arguments, but produce different results:

shell> mysql
86

The first command line displays general help, and ignores the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
714 command. The second command line displays help for the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
714 command.

Suppose that you want to establish two login paths named

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
719 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
720 for connecting to the local MySQL server and a server on the host
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
11. You want to authenticate to the local server with a user name and password of
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
722 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
723, and to the remote server with a user name and password of
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
724 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
725. To set up the login paths in the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file, use the following
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
714 commands. Enter each command on a single line, then enter the appropriate password when prompted.

shell> mysql
87

To see what wrote to the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file, use the
shell> mysql
273 command:

shell> mysql
88

The

shell> mysql
273 command displays each login path as a set of lines beginning with a group header indicating the login path name in square brackets, followed by the option values for the login path. Password values are masked and do not appear as clear text.

As shown by the preceding examples, the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file can contain multiple login paths. In this way, makes it easy to set up multiple “personalities” for connecting to different MySQL servers. Any of these can be selected by name later using the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
08 option when you invoke a client program. For example, to connect to the local server, use this command:

shell> mysql
89

To connect to the remote server, use this command:

shell> mysql
90

When you use the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
714 command with to create a login path, you need not specify all three possible option values (host name, user name, and password). Only those values given are written to the path. Any missing values required later can be specified when you invoke a client path to connect to the MySQL server, either in other option files or on the command line. Also, any options specified on the command line override those in option files, including the
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file. For example, if the credentials in the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
720 login path also apply for the host
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
736, you can connect to the server on that host like this:

shell> mysql
91

The

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
03 file, if it exists, is read in all cases, even when the option is used. This permits passwords to be specified in a safer way than on the command line even if is present.

Commands

This section describes the permitted commands, and the interpretation of options that have a command-specific meaning. In addition, takes other options that can be used with any command, such as

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
62 to produce more information as executes. This option may be helpful in diagnosing problems if an operation does not have the effect you expect. For a list of supported options, see .

supports these commands:

  • shell> mysql
    
    207

    Display a help message and exit.

  • print [

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    259]

    Print the contents of

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 in unencrypted form. Passwords are displayed as
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    744.

    The

    shell> mysql
    
    273 command takes these options:

    If no login path is specified, the default path name is

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    746. If both and are given, takes precedence.

  • remove [

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    259]

    Remove a login path from the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 file.

    The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command takes these options:

    • Remove the host name from the login path.

    • The login path to remove. If this option is not given, the default path name is

      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      746.

    • Remove the password from the login path.

    • Remove the TCP/IP port number from the login path.

    • Remove the Unix socket file name from the login path.

    • Remove the user name from the login path.

    The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    66,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    68, and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    70 options are supported for the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command as of MySQL 5.6.9. The and options are supported for the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command as of MySQL 5.6.11

    The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command removes from the login path only such values as are specified with the , , , , and options. If none of them is given,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 removes the entire login path. For example, this command removes only the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    05 value from the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    746 login path rather than the entire
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    746 login path:

    shell> mysql
    
    92
  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    777

    Empty the contents of the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 file. The file is created if it does not exist.

  • set [

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    259]

    Write a login path to the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 file.

    The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command takes these options:

    The and options are supported for the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command as of MySQL 5.6.11

    The

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command writes to the login path only such values as are specified with the , , , , and options. If none of those options are given, writes the login path as an empty group.

    To specify an empty password, use the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command with the option, then press Enter at the password prompt. The resulting login path written to
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 will include a line like this:

    shell> mysql
    
    93

    If the login path already exists in

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03, the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command replaces it. To ensure that this is what the user wants, prints a warning and prompts for confirmation. To suppress the warning and prompt, use the option.

Options

supports the following options.

Table 4.11. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
695 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit. If preceded by a command name such as

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715, displays information about that command.

  • For the

    shell> mysql
    
    273 command, print all login paths in the login file.

  • ,

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    16

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    808.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, the host name to write to to the login path. For the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command, removes the host name from the login path.

  • , -G

    shell> mysql
    
    837

    For the

    shell> mysql
    
    273,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715, and
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 commands, the login path to use in the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    03 login file.

    Client programs also support the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    08 option, to enable users to specify which login path to use for connecting to a MySQL server. For client programs,
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    08 must be the first option given, which is not true for . See .

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, cause to prompt for a password and write the value entered by the user to the login path. After starts and displays the prompt, the user should type the password and press Enter. To prevent other users from seeing the password, does not echo it.

    This option does not permit a password value following the option name. That is, with , you never enter a password on the command line where it might be seen by other users. This differs from most other MySQL programs, which permit the password to be given on the command line as

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    69 or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    71. (That practice is insecure and should be avoided, however.)

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command, removes the password from the login path.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, the TCP/IP port number to write to the login path. For the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command, removes the port number from the login path.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    41

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, the Unix socket file name to write to the login path. For the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command, removes the socket file from the login path.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, the user name to write to the login path. For the
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    715 command, removes the user name from the login path.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

  • ,

    shell> mysql
    
    191

    For the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    714 command, warn and prompt the user for confirmation if the command attempts to overwrite an existing login path. This option is enabled by default; use to disable it.

4.6.7. mysqlaccess — Client for Checking Access Privileges

is a diagnostic tool that Yves Carlier has provided for the MySQL distribution. It checks the access privileges for a host name, user name, and database combination. Note that checks access using only the

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
05 and
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
848 tables. It does not check table, column, or routine privileges specified in the
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
849,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
850, or
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
851 tables.

Invoke like this:

shell> mysql
94

supports the following options.

Table 4.12. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
852 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • ,

    shell> mysql
    
    098

    Generate reports in single-line tabular format.

  • Copy the new access privileges from the temporary tables to the original grant tables. The grant tables must be flushed for the new privileges to take effect. (For example, execute a command.)

  • Reload the temporary grant tables from original ones.

  • , -d

    shell> mysql
    
    102

    Specify the database name.

  • Specify the debug level.

    shell> mysql --port=13306 --host=localhost
    
    41 can be an integer from 0 to 3.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    The host name to use in the access privileges.

  • Display some examples that show how to use .

  • Assume that the server is an old MySQL server (before MySQL 3.21) that does not yet know how to handle full

    shell> mysql
    
    409 clauses.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you omit the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See .

  • Display suggestions and ideas for future releases.

  • Show the privilege differences after making changes to the temporary grant tables.

  • Display the release notes.

  • , -H

    shell> mysql --host=remote.example.com
    
    83

    Connect to the MySQL server on the given host.

  • Undo the most recent changes to the temporary grant tables.

  • , -P[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server as the superuser. If you omit the

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See .

  • , -U

    shell> mysql --port=13306 --host=localhost
    
    01

    Specify the user name for connecting as the superuser.

  • ,

    shell> mysql
    
    176

    Generate reports in table format.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The user name to use in the access privileges.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Display version information and exit.

If your MySQL distribution is installed in some nonstandard location, you must change the location where expects to find the client. Edit the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
852 script at approximately line 18. Search for a line that looks like this:

shell> mysql
95

Change the path to reflect the location where actually is stored on your system. If you do not do this, a

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
893 error will occur when you run .

4.6.8. mysqlbinlog — Utility for Processing Binary Log Files

The server's binary log consists of files containing “events” that describe modifications to database contents. The server writes these files in binary format. To display their contents in text format, use the utility. You can also use to display the contents of relay log files written by a slave server in a replication setup because relay logs have the same format as binary logs. The binary log and relay log are discussed further in , and .

Invoke like this:

shell> mysql
96

For example, to display the contents of the binary log file named

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
894, use this command:

shell> mysql
97

The output includes events contained in

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
894. For statement-based logging, event information includes the SQL statement, the ID of the server on which it was executed, the timestamp when the statement was executed, how much time it took, and so forth. For row-based logging, the event indicates a row change rather than an SQL statement. See , for information about logging modes.

Events are preceded by header comments that provide additional information. For example:

shell> mysql
98

In the first line, the number following

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
896 indicates the starting position of the event in the binary log file.

The second line starts with a date and time indicating when the statement started on the server where the event originated. For replication, this timestamp is propagated to slave servers.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
897 is the value of the server where the event originated.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
899 indicates where the next event starts (that is, it is the end position of the current event + 1).
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
900 indicates which thread executed the event.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
901 is the time spent executing the event, on a master server. On a slave, it is the difference of the end execution time on the slave minus the beginning execution time on the master. The difference serves as an indicator of how much replication lags behind the master.
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
902 indicates the result from executing the event. Zero means that no error occurred.

The output from can be re-executed (for example, by using it as input to ) to redo the statements in the log. This is useful for recovery operations after a server crash. For other usage examples, see the discussion later in this section and in .

Normally, you use to read binary log files directly and apply them to the local MySQL server. It is also possible to read binary logs from a remote server by using the option. To read remote binary logs, the connection parameter options can be given to indicate how to connect to the server. These options are , , , , , and ; they are ignored except when you also use the option.

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
911 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. also supports the options for processing option files described at .

Table 4.13. 

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
913 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • This option determines when events should be displayed encoded as base-64 strings using statements. The option has these permissible values (not case sensitive):

    • shell> mysql
      
      823 ("automatic") or
      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      919 ("unspecified") displays statements automatically when necessary (that is, for format description events and row events). If no option is given, the effect is the same as .

      Automatic display is the only safe behavior if you intend to use the output of to re-execute binary log file contents. The other option values are intended only for debugging or testing purposes because they may produce output that does not include all events in executable form.

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      924 causes statements not to be displayed. exits with an error if a row event is found that must be displayed using .

    • shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      927 specifies to that you intend for row events to be decoded and displayed as commented SQL statements by also specifying the option. Like
      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      924,
      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      927 suppresses display of statements, but unlike
      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      924, it does not exit with an error if a row event is found.

    For examples that show the effect of and on row event output, see .

  • On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

    This option is supported beginning with MySQL 5.6.1.

  • Command-Line Format

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    937Option-File Format
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    938Permitted ValuesPlatform Bit Size
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    939Type
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    940Default
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    941Range
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    942

    Specify the maximum size of a row-based binary log event, in bytes. Rows are grouped into events smaller than this size if possible. The value should be a multiple of 256. The default is 4GB.

  • The directory where character sets are installed. See .

  • , -d

    shell> mysql
    
    102

    This option causes to output entries from the binary log (local log only) that occur while

    shell> mysql
    
    102 is been selected as the default database by .

    The option for is similar to the option for , but can be used to specify only one database. If is given multiple times, only the last instance is used.

    The effects of this option depend on whether the statement-based or row-based logging format is in use, in the same way that the effects of depend on whether statement-based or row-based logging is in use.

    Statement-based logging.  The option works as follows:

    • While

      shell> mysql
      
      102 is the default database, statements are output whether they modify tables in
      shell> mysql
      
      102 or a different database.

    • Unless

      shell> mysql
      
      102 is selected as the default database, statements are not output, even if they modify tables in
      shell> mysql
      
      102.

    • There is an exception for , , and . The database being created, altered, or dropped is considered to be the default database when determining whether to output the statement.

    Suppose that the binary log was created by executing these statements using statement-based-logging:

    shell> mysql
    
    99

    does not output the first two statements because there is no default database. It outputs the three statements following , but not the three statements following .

    does not output the first two statements because there is no default database. It does not output the three statements following , but does output the three statements following .

    Row-based logging.  outputs only entries that change tables belonging to

    shell> mysql
    
    102. The default database has no effect on this. Suppose that the binary log just described was created using row-based logging rather than statement-based logging. outputs only those entries that modify
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    971 in the test database, regardless of whether was issued or what the default database is.

    If a server is running with set to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    974 and you want it to be possible to use with the option, you must ensure that tables that are modified are in the database selected by . (In particular, no cross-database updates should be used.)

    Prior to MySQL 5.6.10, the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    948 option did not work correctly with a log written by a GTID-enabled MySQL server. (Bug #15912728)

  • , -# [

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17]

    Write a debugging log. A typical

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    17 string is 'd:t:o,
    shell> mysql --host=remote.example.com
    
    38'
    . The default is
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    982.

  • Print some debugging information when the program exits.

  • Print debugging information and memory and CPU usage statistics when the program exits.

  • The client-side authentication plugin to use. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    987

    Disable binary logging. This is useful for avoiding an endless loop if you use the option and are sending the output to the same MySQL server. This option also is useful when restoring after a crash to avoid duplication of the statements you have logged.

    This option requires that you have the privilege. It causes to include a

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    990 statement in its output to disable binary logging of the remaining output. The statement is ineffective unless you have the privilege.

  • Do not display any of the groups listed in the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    994. Added in MySQL 5.6.5.

  • ,

    shell> mysql
    
    311

    Read binary log files even if they are open or were not closed properly.

  • ,

    shell> mysql
    
    068

    With this option, if reads a binary log event that it does not recognize, it prints a warning, ignores the event, and continues. Without this option, stops if it reads such an event.

  • ,

    shell> mysql
    
    073

    Display a hex dump of the log in comments, as described in . The hex output can be helpful for replication debugging.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Get the binary log from the MySQL server on the given host.

  • Display only the groups listed in the

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    994. Added in MySQL 5.6.5.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    006

    Prepare local temporary files for in the specified directory.

    These temporary files are not automatically removed by or any other MySQL program.

  • , -o

    shell> mysql --port=13306 --host=localhost
    
    41

    Skip the first

    shell> mysql --port=13306 --host=localhost
    
    41 entries in the log.

  • , -p[

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06]

    The password to use when connecting to the server. If you use the short option form (

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71), you cannot have a space between the option and the password. If you omit the
    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06 value following the or
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    71 option on the command line, prompts for one.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • The directory in which to look for plugins. It may be necessary to specify this option if the option is used to specify an authentication plugin but does not find it. See .

    This option was added in MySQL 5.6.2.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use for connecting to a remote server.

  • The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see .

  • By default, reads binary log files and writes events in text format. The option tells to write them in their original binary format. Its use requires that also be used because the files are requested from a server. writes one output file for each file read from the server. The option can be used to make a backup of a server's binary log. With the option, the backup is “live” because stays connected to the server. By default, output files are written in the current directory with the same names as the original log files. Output file names can be modified using the option. For more information, see .

    This option was added in MySQL 5.6.0.

  • Read binary logs from a MySQL server with the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    029 or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    030 commands by setting the option value to either
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    031 or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    032, respectively. If is combined with , transactions can be filtered out on the master, avoiding unnecessary network traffic.

    See also the description for .

    This option was added in MySQL 5.6.5.

  • ,

    shell> mysql
    
    936

    Read the binary log from a MySQL server rather than reading a local log file. Any connection parameter options are ignored unless this option is given as well. These options are , , , , , and .

    This option requires that the remote server be running. It works only for binary log files on the remote server, not relay log files.

    As of MySQL 5.6.5, this option is like .

  • , -r

    shell> mysql
    
    837

    Without the option, this option indicates the file to which writes text output. With , writes one binary output file for each log file transferred from the server, writing them by default in the current directory using the same names as the original log file. In this case, the option value is treated as a prefix that modifies output file names.

  • Display only those events created by the server having the given server ID.

  • Add a SET NAMES

    shell> mysql
    
    054 statement to the output to specify the character set to be used for processing log files.

  • ,

    shell> mysql --host=localhost
    
    95

    Display only the statements contained in the log, without any extra information or row-based events. This is for testing only, and should not be used in production systems.

  • Do not display any GTIDs. Not recommended in production. Added in MySQL 5.6.5.

  • ,

    shell> mysql
    
    171

    For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • Start reading the binary log at the first event having a timestamp equal to or later than the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    060 argument. The
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    060 value is relative to the local time zone on the machine where you run . The value should be in a format accepted for the or data types. For example:

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    00

    This option is useful for point-in-time recovery. See .

  • , -j

    shell> mysql --port=13306 --host=localhost
    
    41

    Start reading the binary log at the first event having a position equal to or greater than

    shell> mysql --port=13306 --host=localhost
    
    41. This option applies to the first log file named on the command line.

    This option is useful for point-in-time recovery. See .

  • Stop reading the binary log at the first event having a timestamp equal to or later than the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    060 argument. This option is useful for point-in-time recovery. See the description of the option for information about the
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    060 value.

    This option is useful for point-in-time recovery. See .

  • This option is used with . It tells to remain connected to the server. Otherwise exits when the last log file has been transferred from the server. implies , so only the first log file to transfer need be named on the command line.

    is commonly used with to make a live binary log backup, but also can be used without to maintain a continuous text display of log events as the server generates them.

    This option was added in MySQL 5.6.0.

  • With , reports a server ID of 65535 when it connects to the server. explicitly specifies the server ID to report. It can be used to avoid a conflict with the ID of a slave server or another process. See .

    This option was added in MySQL 5.6.0.

  • Stop reading the binary log at the first event having a position equal to or greater than

    shell> mysql --port=13306 --host=localhost
    
    41. This option applies to the last log file named on the command line.

    This option is useful for point-in-time recovery. See .

  • ,

    shell> mysql
    
    176

    Do not stop at the end of the requested binary log from a MySQL server, but rather continue printing until the end of the last binary log. If you send the output to the same MySQL server, this may lead to an endless loop. This option requires .

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to a remote server.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Reconstruct row events and display them as commented SQL statements. If this option is given twice, the output includes comments to indicate column data types and some metadata.

    For examples that show the effect of and on row event output, see .

  • ,

    shell> mysql
    
    039

    Verify checksums in binary log files. This option was added in MySQL 5.6.1.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

You can also set the following variable by using

shell> mysql
196=
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
81 syntax:

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    098

    Specify the number of open file descriptors to reserve.

You can pipe the output of into the client to execute the events contained in the binary log. This technique is used to recover from a crash when you have an old backup (see ). For example:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
01

Or:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
02

If the statements produced by may contain values, these may cause problems when processes them. In this case, invoke with the option.

You can also redirect the output of to a text file instead, if you need to modify the statement log first (for example, to remove statements that you do not want to execute for some reason). After editing the file, execute the statements that it contains by using it as input to the program:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
03

When is invoked with the option, it displays only those events with an offset in the binary log greater than or equal to a given position (the given position must match the start of one event). It also has options to stop and start when it sees an event with a given date and time. This enables you to perform point-in-time recovery using the option (to be able to say, for example, “roll forward my databases to how they were today at 10:30 a.m.”).

If you have more than one binary log to execute on the MySQL server, the safe method is to process them all using a single connection to the server. Here is an example that demonstrates what may be unsafe:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
04

Processing binary logs this way using multiple connections to the server causes problems if the first log file contains a statement and the second log contains a statement that uses the temporary table. When the first process terminates, the server drops the temporary table. When the second process attempts to use the table, the server reports “unknown table.”

To avoid problems like this, use a single process to execute the contents of all binary logs that you want to process. Here is one way to do so:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
05

Another approach is to write all the logs to a single file and then process the file:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
06

can produce output that reproduces a operation without the original data file. copies the data to a temporary file and writes a statement that refers to the file. The default location of the directory where these files are written is system-specific. To specify a directory explicitly, use the option.

Because converts statements to statements (that is, it adds

shell> mysql
081), both the client and the server that you use to process the statements must be configured with the
shell> mysql
081 capability enabled. See .

The temporary files created for statements are not automatically deleted because they are needed until you actually execute those statements. You should delete the temporary files yourself after you no longer need the statement log. The files can be found in the temporary file directory and have names like

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
113.

4.6.8.1. mysqlbinlog Hex Dump Format

The option causes to produce a hex dump of the binary log contents:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
07

The hex output consists of comment lines beginning with

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
73, so the output might look like this for the preceding command:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
08

Hex dump output currently contains the elements in the following list. This format is subject to change. (For more information about binary log format, see MySQL Internals: The Binary Log.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    116: The byte position within the log file.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    117: The event timestamp. In the example shown,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    118 is the representation of
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    119 in hexadecimal.

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    515: The event type code. In the example shown,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    121 indicates a
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    122. The following table lists the possible type codes.

    TypeNameMeaning

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    123
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    124This event should never be present in the log.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    125
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    126This indicates the start of a log file written by MySQL 4 or earlier.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    127
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    128The most common type of events. These contain statements executed on the master.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    129
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    130Indicates that master has stopped.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    131
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    132Written when the master switches to a new log file.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    133
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    134Used for
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    119 values or when the function is used in the statement.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    137
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    138Used for in MySQL 3.23.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    140
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    141Reserved for future use.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    142
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    143Used for statements. This indicates the start of execution of such a statement. A temporary file is created on the slave. Used in MySQL 4 only.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    145
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    146Contains data for use in a statement. The data is stored in the temporary file on the slave.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    148
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    149Used for statements. The contents of the temporary file is stored in the table on the slave. Used in MySQL 4 only.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    151
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    152Rollback of a statement. The temporary file should be deleted on the slave.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    154
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    155Used for in MySQL 4 and earlier.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    157
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    158Used to send information about random values if the function is used in the statement.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    160
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    161Used to replicate user variables.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    162
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    122This indicates the start of a log file written by MySQL 5 or later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    164
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    165Event indicating commit of an XA transaction.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    166
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    167Used for statements in MySQL 5 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    169
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    170Used for statements in MySQL 5 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    172
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    173Information about a table definition. Used in MySQL 5.1.5 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    174
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    175Row data for a single table that should be created. Used in MySQL 5.1.5 to 5.1.17.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    176
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    177Row data for a single table that needs to be updated. Used in MySQL 5.1.5 to 5.1.17.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    178
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    179Row data for a single table that should be deleted. Used in MySQL 5.1.5 to 5.1.17.
    shell> mysql --port=13306 --host=localhost
    
    53
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    181Row data for a single table that should be created. Used in MySQL 5.1.18 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    182
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    183Row data for a single table that needs to be updated. Used in MySQL 5.1.18 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    184
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    185Row data for a single table that should be deleted. Used in MySQL 5.1.18 and later.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    186
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    187Something out of the ordinary happened. Added in MySQL 5.1.18.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    188: The server ID of the master that created the event.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    189: The size in bytes of the event.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    190: The position of the next event in the original master log file.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    191: 16 flags. Currently, the following flags are used. The others are reserved for future use.

    FlagNameMeaning

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    125
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    193Log file correctly closed. (Used only in
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    122.) If this flag is set (if the flags are, for example,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    195) in a
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    122, the log file has not been properly closed. Most probably this is because of a master crash (for example, due to power failure).
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    127Reserved for future use.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    131
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    199Set if the event is dependent on the connection it was executed in (for example,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    200), for example, if the event uses temporary tables.
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    142
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    202Set in some circumstances when the event is not dependent on the default database.

4.6.8.2. mysqlbinlog Row Event Display

The following examples illustrate how displays row events that specify data modifications. These correspond to events with the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
181,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
183, and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
185 type codes. The and options may be used to affect row event output.

Suppose that the server is using row-based binary logging and that you execute the following sequence of statements:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
09

By default, displays row events encoded as base-64 strings using statements. Omitting extraneous lines, the output for the row events produced by the preceding statement sequence looks like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
10

To see the row events as comments in the form of “pseudo-SQL” statements, run with the or

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
60 option. The output will contain lines beginning with
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
211:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
11

Specify or

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
60 twice to also display data types and some metadata for each column. The output will contain an additional comment following each column change:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
12

You can tell to suppress the statements for row events by using the option. This is similar to but does not exit with an error if a row event is found. The combination of and provides a convenient way to see row events only as SQL statements:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
13

You should not suppress statements if you intend to re-execute output.

The SQL statements produced by for row events are much more readable than the corresponding statements. However, they do not correspond exactly to the original SQL statements that generated the events. The following limitations apply:

  • The original column names are lost and replaced by @

    shell> mysql --port=13306 --host=localhost
    
    41, where
    shell> mysql --port=13306 --host=localhost
    
    41 is a column number.

  • Character set information is not available in the binary log, which affects string column display:

    • There is no distinction made between corresponding binary and nonbinary string types ( and , and , and ). The output uses a data type of

      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      230 for fixed-length strings and
      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      231 for variable-length strings.

    • For multi-byte character sets, the maximum number of bytes per character is not present in the binary log, so the length for string types is displayed in bytes rather than in characters. For example,

      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      232 will be used as the data type for values from either of these column types:

      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      14
    • Due to the storage format for events of type

      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      183, statements are displayed with the
      shell> mysql
      
      409 clause preceding the
      shell> mysql --host=remote.example.com
      
      59 clause.

Proper interpretation of row events requires the information from the format description event at the beginning of the binary log. Because does not know in advance whether the rest of the log contains row events, by default it displays the format description event using a statement in the initial part of the output.

If the binary log is known not to contain any events requiring a statement (that is, no row events), the option can be used to prevent this header from being written.

4.6.8.3. Using mysqlbinlog to Back Up Binary Log Files

By default, reads binary log files and displays their contents in text format. This enables you to examine events within the files more easily or be re-execute them (for example, by using the output as input to ). can read log files directly from the local file system, or, with the option, it can connect to a server and request binary log contents from that server. writes text output to its standard output, or to the file named as the value of the option if that option is given.

As of MySQL 5.6, can read binary log files and write new files containing the same content—that is, in binary format rather than text format. This capability enables you to easily back up a binary log in its original format. can make a static backup, backing up a set of log files and stopping when the end of the last file is reached. It can also make a continuous (“live”) backup, staying connected to the server when it reaches the end of the last log file and continuing to copy new events as they are generated. In continuous-backup operation, runs until the connection ends (for example, when the server exits) or is forcibly terminated. When the connection ends, does not wait and retry the connection, unlike a slave replication server. To continue a live backup after the server has been restarted, you must also restart .

Binary log backup requires that you invoke with two options at minimum:

  • The (or

    shell> mysql
    
    936) option tells to connect to a server and request its binary log. (This is similar to a slave replication server connecting to its master server.)

  • The option tells to write raw (binary) output, not text output.

Along with , it is common to specify other options: indicates where the server is running, and you may also need to specify connection options such as and .

Several other options are useful in conjunction with :

To back up a server's binary log files with , you must specify file names that actually exist on the server. If you do not know the names, connect to the server and use the statement to see the current names. Suppose that the statement produces this output:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
15

With that information, you can use to back up the binary log to the current directory as follows (enter each command on a single line):

  • To make a static backup of

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    251 through
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    252, use either of these commands:

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    16

    The first command specifies every file name explicitly. The second names only the first file and uses to read through the last. A difference between these commands is that if the server happens to open

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    254 before reaches the end of
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    252, the first command will not read it, but the second command will.

  • To make a live backup in which starts with

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    251 to copy existing log files, then stays connected to copy new events as the server generates them:

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    17

    With , it is not necessary to specify to read to the last log file because that option is implied.

Output File Naming

Without , produces text output and the option, if given, specifies the name of the single file to which all output is written. With , writes one binary output file for each log file transferred from the server. By default, writes the files in the current directory with the same names as the original log files. To modify the output file names, use the option. In conjunction with , the option value is treated as a prefix that modifies the output file names.

Suppose that a server currently has binary log files named

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
265 and up. If you use to back up the files, the option produces output file names as shown in the following table. You can write the files to a specific directory by beginning the value with the directory path. If the value consists only of a directory name, the value must end with the pathname separator character. Output files are overwritten if they exist.

Example: + for Backup and Restore

The following example describes a simple scenario that shows how to use and together to back up a server's data and binary log, and how to use the backup to restore the server if data loss occurs. The example assumes that the server is running on host

shell> mysql --host=remote.example.com
83 and its first binary log file is named
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
265. Enter each command on a single line.

Use to make a continuous backup of the binary log:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
18

Use to create a dump file as a snapshot of the server's data. Use , , and to back up all data, and to include the current binary log coordinates in the dump file.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
19

Execute the command periodically to create newer snapshots as desired.

If data loss occurs (for example, if the server crashes), use the most recent dump file to restore the data:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
20

Then use the binary log backup to re-execute events that were written after the coordinates listed in the dump file. Suppose that the coordinates in the file look like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
21

If the most recent backed-up log file is named

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
275, re-execute the log events like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
22

You might find it easier to copy the backup files (dump file and binary log files) to the server host to make it easier to perform the restore operation, or if MySQL does not allow remote

shell> mysql --host=remote.example.com --port=13306
76 access.

4.6.8.4. Specifying the mysqlbinlog Server ID

When invoked with the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
903 option, connects to a MySQL server, specifies a server ID to identify itself, and requests binary log files from the server. You can use to request log files from a server in several ways:

  • Specify an explicitly named set of files: For each file, connects and issues a

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    278 command. The server sends the file and disconnects. There is one connection per file.

  • Specify the beginning file and : connects and issues a

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    278 command for all files. The server sends all files and disconnects.

  • Specify the beginning file and (which implies ): connects and issues a

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    278 command for all files. The server sends all files, but does not disconnect after sending the last one.

With only, connects using a server ID of 0, which tells the server to disconnect after sending the last requested log file.

With and , connects using a nonzero server ID, so the server does not disconnect after sending the last log file. The server ID is 65535 by default, but this can be changed with .

Thus, for the first two ways of requesting files, the server disconnects because specifies a server ID of 0. It does not disconnect if is given because specifies a nonzero server ID.

4.6.9. mysqldumpslow — Summarize Slow Query Log Files

The MySQL slow query log contains information about queries that take a long time to execute (see ). parses MySQL slow query log files and prints a summary of their contents.

Normally, groups queries that are similar except for the particular values of number and string data values. It “abstracts” these values to

shell> mysql --port=13306 --host=localhost
41 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
290 when displaying summary output. The
shell> mysql
587 and
shell> mysql
179 options can be used to modify value abstracting behavior.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
23

supports the following options.

Table 4.14. 

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
293 Options

FormatOption FileDescriptionDo not abstract all numbers to N and strings to SAbstract numbers with at least the specified digitsWrite debugging informationOnly consider statements that match the patternDisplay help message and exitHost name of the server in the log file nameName of the server instanceDo not subtract lock time from total timeReverse the sort orderHow to sort outputDisplay only first num queriesVerbose mode


  • Display a help message and exit.

  • shell> mysql
    
    587

    Do not abstract all numbers to

    shell> mysql --port=13306 --host=localhost
    
    41 and strings to
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    290.

  • ,

    shell> mysql
    
    933

    Run in debug mode.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    300

    Consider only queries that match the (grep-style) pattern.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    Host name of MySQL server for

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    302 file name. The value can contain a wildcard. The default is
    shell> mysql
    
    384 (match all).

  • -i

    shell> mysql
    
    837

    Name of server instance (if using startup script).

  • shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    016

    Do not subtract lock time from total time.

  • -n

    shell> mysql --port=13306 --host=localhost
    
    41

    Abstract numbers with at least

    shell> mysql --port=13306 --host=localhost
    
    41 digits within names.

  • shell> mysql
    
    136

    Reverse the sort order.

  • shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    309

    How to sort the output. The value of

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    310 should be chosen from the following list:

    • shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      311,
      shell> mysql --host=localhost --user=myname --password=mypass mydb
      shell> mysql -h localhost -u myname -pmypass mydb
      
      896: Sort by query time or average query time

    • shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      313,
      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      314: Sort by lock time or average lock time

    • shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      315,
      shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      316: Sort by rows sent or average rows sent

    • shell> mysql --host=localhost --user=myname --password mydb
      shell> mysql -h localhost -u myname -p mydb
      
      317: Sort by count

    By default, sorts by average query time (equivalent to

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    318).

  • -t

    shell> mysql --port=13306 --host=localhost
    
    41

    Display only the first

    shell> mysql --port=13306 --host=localhost
    
    41 queries in the output.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print more information about what the program does.

Example of usage:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
24

4.6.10. mysqlhotcopy — A Database Backup Program

is a Perl script that was originally written and contributed by Tim Bunce. It uses , , and

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
325 or
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
326 to make a database backup. It is a fast way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located. works only for backing up
shell> mysql
004 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
328 tables. It runs on Unix.

To use , you must have read access to the files for the tables that you are backing up, the privilege for those tables, the privilege (to be able to execute ), and the privilege (to be able to lock the tables).

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
25
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
26

Back up tables in the given database that match a regular expression:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
27

The regular expression for the table name can be negated by prefixing it with a tilde (“

shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
35”):

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
28

supports the following options, which can be specified on the command line or in the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
334 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 groups of an option file. For information about option files, see .

Table 4.15. 

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
336 Options


  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • Do not rename target directory (if it exists); merely add files to it.

  • Do not abort if a target exists; rename it by adding an

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    341 suffix.

  • Insert checkpoint entries into the specified database

    shell> mysql
    
    102 and table
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    227.

  • Base directory of the chroot jail in which operates. The

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    347 value should match that of the option given to .

  • Enable debug output.

  • ,

    shell> mysql
    
    179

    Report actions without performing them.

  • Flush logs after all tables are locked.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    17

    The host name of the local host to use for making a TCP/IP connection to the local server. By default, the connection is made to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52 using a Unix socket file.

  • Do not delete previous (renamed) target when done.

  • The method for copying files (

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    325 or
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    326). The default is
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    325.

  • Do not include full index files for tables in the backup. This makes the backup smaller and faster. The indexes for reloaded tables can be reconstructed later with .

  • , -p

    shell> mysql --host=127.0.0.1
    shell> mysql --protocol=TCP
    
    06

    The password to use when connecting to the server. The password value is not optional for this option, unlike for other MySQL programs.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    27

    The TCP/IP port number to use when connecting to the local server.

  • In MySQL 5.6, uses to flush and lock tables. Use the option if the server is older than 5.5.3, which is when that statement was introduced.

  • ,

    shell> mysql
    
    134

    Be silent except for errors.

  • Record master and slave status in the specified database

    shell> mysql
    
    102 and table
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    227.

  • Copy all databases with names that match the given regular expression.

  • Reset the binary log after locking all the tables.

  • Reset the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    379 file after locking all the tables.

  • ,

    shell> mysql
    
    171

    The Unix socket file to use for connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52.

  • The suffix to use for names of copied databases.

  • The temporary directory. The default is

    shell> mysql --port=13306 --host=127.0.0.1
    shell> mysql --port=13306 --protocol=TCP
    
    60.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    48

    The MySQL user name to use when connecting to the server.

Use

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
388 for additional documentation, including information about the structure of the tables needed for the and options:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
29

4.6.11. mysql_convert_table_format — Convert Tables to Use a Given Storage Engine

converts the tables in a database to use a particular storage engine (

shell> mysql
004 by default). is written in Perl and requires that the
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
392 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
393 Perl modules be installed (see ).

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
30

The

shell> mysql
102 argument indicates the database containing the tables to be converted.

supports the options described in the following list.

  • Display a help message and exit.

  • Continue even if errors occur.

  • Connect to the MySQL server on the given host.

  • The password to use when connecting to the server. Note that the password value is not optional for this option, unlike for other MySQL programs.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • The TCP/IP port number to use for the connection.

  • For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use.

  • Specify the storage engine that the tables should be converted to use. The default is

    shell> mysql
    
    004 if this option is not given.

  • The MySQL user name to use when connecting to the server.

  • Verbose mode. Print more information about what the program does.

  • Display version information and exit.

4.6.12. mysql_find_rows — Extract SQL Statements from Files

reads files containing SQL statements and extracts statements that match a given regular expression or that contain USE

shell> mysql
102 or statements. The utility expects statements to be terminated with semicolon (
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
74) characters.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
31

Each

shell> mysql --host=remote.example.com
38 argument should be the name of file containing SQL statements. If no file names are given, reads the standard input.

Examples:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
32

supports the following options:

4.6.13. mysql_fix_extensions — Normalize Table File Name Extensions

converts the extensions for

shell> mysql
004 (or
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
412) table files to their canonical forms. It looks for files with extensions matching any lettercase variant of
shell> mysql
658,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
414,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
415,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
416, and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
417 and renames them to have extensions of
shell> mysql
658,
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
252,
shell> mysql
659,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
421, and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
422, respectively. This can be useful after transferring the files from a system with case-insensitive file names (such as Windows) to a system with case-sensitive file names.

Invoke like this, where

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
423 is the path name to the MySQL data directory.

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
33

4.6.14. mysql_setpermission — Interactively Set Permissions in Grant Tables

is a Perl script that was originally written and contributed by Luuk de Boer. It interactively sets permissions in the MySQL grant tables. is written in Perl and requires that the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
392 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
393 Perl modules be installed (see ).

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
34

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
259 should be either to display the help message, or options that indicate how to connect to the MySQL server. The account used when you connect determines which permissions you have when attempting to modify existing permissions in the grant tables.

mysql_setpermissions also reads options from the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
429 groups in the
shell> mysql
366 file in your home directory, if the file exists.

supports the following options:

  • Display a help message and exit.

  • Connect to the MySQL server on the given host.

  • The password to use when connecting to the server. Note that the password value is not optional for this option, unlike for other MySQL programs.

    Specifying a password on the command line should be considered insecure. See . You can use an option file to avoid giving the password on the command line.

  • The TCP/IP port number to use for the connection.

  • For connections to

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    52, the Unix socket file to use.

  • The MySQL user name to use when connecting to the server.

4.6.15. mysql_waitpid — Kill Process and Wait for Its Termination

signals a process to terminate and waits for the process to exit. It uses the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
438 system call and Unix signals, so it runs on Unix and Unix-like systems.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
35

sends signal 0 to the process identified by

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
439 and waits up to
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
440 seconds for the process to terminate.
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
439 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
440 must be positive integers.

If process termination occurs within the wait time or the process does not exist, returns 0. Otherwise, it returns 1.

If the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
438 system call cannot handle signal 0, mysql_waitpid() uses signal 1 instead.

supports the following options:

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    605

    Display a help message and exit.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Display a warning if signal 0 could not be used and signal 1 is used instead.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

4.6.16. mysql_zap — Kill Processes That Match a Pattern

kills processes that match a pattern. It uses the ps command and Unix signals, so it runs on Unix and Unix-like systems.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
36

A process matches if its output line from the ps command contains the pattern. By default, asks for confirmation for each process. Respond

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
451 to kill the process, or
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
452 to exit . For any other response, does not attempt to kill the process.

If the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
453 option is given, it specifies the name or number of the signal to send to each process. Otherwise, tries first with
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
454 (signal 15) and then with (signal 9).

supports the following additional options:

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58,
    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    605

    Display a help message and exit.

  • shell> mysql
    
    068

    Force mode. attempts to kill each process without confirmation.

  • shell> mysql
    
    176

    Test mode. Display information about each process but do not kill it.

4.7. MySQL Program Development Utilities

This section describes some utilities that you may find useful when developing MySQL programs.

In shell scripts, you can use the program to parse option files and see what options would be used by a given program. The following example shows the output that might produce when asked to show the options found in the

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 and
shell> mysql --host=remote.example.com
08 groups:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
37

Note for developers: Option file handling is implemented in the C client library simply by processing all options in the appropriate group or groups before any command-line arguments. This works well for programs that use the last instance of an option that is specified multiple times. If you have a C or C++ program that handles multiply specified options this way but that doesn't read option files, you need add only two lines to give it that capability. Check the source code of any of the standard MySQL clients to see how to do this.

Several other language interfaces to MySQL are based on the C client library, and some of them provide a way to access option file contents. These include Perl and Python. For details, see the documentation for your preferred interface.

4.7.1. msql2mysql — Convert mSQL Programs for Use with MySQL

Initially, the MySQL C API was developed to be very similar to that for the mSQL database system. Because of this, mSQL programs often can be converted relatively easily for use with MySQL by changing the names of the C API functions.

The utility performs the conversion of mSQL C API function calls to their MySQL equivalents. converts the input file in place, so make a copy of the original before converting it. For example, use like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
38

Then examine

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
463 and make any post-conversion revisions that may be necessary.

uses the utility to make the function name substitutions. See .

4.7.2. mysql_config — Get Compile Options for Compiling Clients

provides you with useful information for compiling your MySQL client and connecting it to MySQL.

supports the following options.

  • C Compiler flags to find include files and critical compiler flags and defines used when compiling the

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    465 library. The options returned are tied to the specific compiler that was used when the library was created and might clash with the settings for your own compiler. Use for more portable options that contain only include paths.

  • Like , but for C++ compiler flags. This option was added in MySQL 5.6.4.

  • Compiler options to find MySQL include files.

  • ,

    Libraries and options required to link with the MySQL embedded server.

  • Libraries and options required to link with the MySQL client library.

  • Libraries and options required to link with the thread-safe MySQL client library.

  • The default plugin directory path name, defined when configuring MySQL.

  • The default TCP/IP port number, defined when configuring MySQL.

  • The default Unix socket file, defined when configuring MySQL.

  • Version number for the MySQL distribution.

If you invoke with no options, it displays a list of all options that it supports, and their values:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
39

You can use within a command line to include the value that it displays for a particular option. For example, to compile a MySQL client program, use as follows:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
40

When you use this way, be sure to invoke it within backtick (“

shell> mysql
235”) characters. That tells the shell to execute it and substitute its output into the surrounding command.

4.7.3. my_print_defaults — Display Options from Option Files

displays the options that are present in option groups of option files. The output indicates what options will be used by programs that read the specified option groups. For example, the program reads the

shell> mysql
576 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
50 option groups. To see what options are present in those groups in the standard option files, invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
41

The output consists of options, one per line, in the form that they would be specified on the command line.

supports the following options.

4.7.4. resolve_stack_dump — Resolve Numeric Stack Trace Dump to Symbols

resolves a numeric stack dump to symbols.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
42

The symbols file should include the output from the nm --numeric-sort mysqld command. The numeric dump file should contain a numeric stack track from . If no numeric dump file is named on the command line, the stack trace is read from the standard input.

supports the following options.

4.8. Miscellaneous Programs

4.8.1. perror — Explain Error Codes

For most system errors, MySQL displays, in addition to an internal text message, the system error code in one of the following styles:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
43

You can find out what the error code means by examining the documentation for your system or by using the utility.

prints a description for a system error code or for a storage engine (table handler) error code.

Invoke like this:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
44

Example:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
45

To obtain the error message for a MySQL Cluster error code, invoke with the option:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
46

Note that the meaning of system error messages may be dependent on your operating system. A given error code may mean different things on different operating systems.

supports the following options.

  • , ,

    shell> mysql --host=localhost --user=myname --password=mypass mydb
    shell> mysql -h localhost -u myname -pmypass mydb
    
    605,
    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    58

    Display a help message and exit.

  • Print the error message for a MySQL Cluster error code.

  • ,

    shell> mysql --host=localhost
    
    95

    Silent mode. Print only the error message.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    60

    Verbose mode. Print error code and message. This is the default behavior.

  • ,

    shell> mysql --host=localhost --user=myname --password mydb
    shell> mysql -h localhost -u myname -p mydb
    
    61

    Display version information and exit.

4.8.2. replace — A String-Replacement Utility

The utility program changes strings in place in files or on the standard input.

Invoke in one of the following ways:

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
47

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
493 represents a string to look for and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
494 represents its replacement. There can be one or more pairs of strings.

Use the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
63 option to indicate where the string-replacement list ends and the file names begin. In this case, any file named on the command line is modified in place, so you may want to make a copy of the original before converting it.
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
496 prints a message indicating which of the input files it actually modifies.

If the

shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb
63 option is not given, reads the standard input and writes to the standard output.

uses a finite state machine to match longer strings first. It can be used to swap strings. For example, the following command swaps

shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
498 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
499 in the given files,
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
500 and
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb
501:

Where is the MySQL config file?

ini C:\Program Files\MySQL\MySQL Server 5.5\my. cnf.

Where is MySQL configuration file in Linux?

Support Network.
Find the configuration files. By default, you can find the MySQL® configuration files in: /etc/mysql. ... .
my. cnf configuration file. ... .
Log files. Log files are the best place to start troubleshooting any program. ... .
mysqld and mysqld_safe. ... .
mysqladmin. ... .
Backups. ... .
Database engine. ... .
Related articles..

How do I access MySQL config?

How to View Mysql Settings in the my..
Login to your server via SSH..
To view the MySQL my.cnf settings type the following: Copy. cat /etc/my.cnf. The contents of the my. cnf file will display similar to the snapshot above..

What is configuration file of MySQL?

Most MySQL programs can read startup options from option files (sometimes called configuration files). Option files provide a convenient way to specify commonly used options so that they need not be entered on the command line each time you run a program.