MySQL 8.4.0
Source Code Documentation
mysqltest — Program to Run Test Cases

The mysqltest program runs a test case against a MySQL server and optionally compares the output with a result file.

This program reads input written in a special test language. Typically, you invoke mysqltest using rather than invoking it directly.

Features of mysqltest:

  • Can send SQL statements to MySQL servers for execution
  • Can execute external shell commands
  • Can test whether the result from an SQL statement or shell command is as expected
  • Can connect to one or more standalone mysqld servers and switch between connections

By default, mysqltest reads the test case on the standard input. To run mysqltest this way, you normally invoke it like this:

shell> mysqltest [options] [db_name] < test_file

You can also name the test case file with a --test- file=file_name option.

The exit value from mysqltest is 0 for success, 1 for failure, and 62 if it skips the test case (for example, if after checking some preconditions it decides not to run the test).

mysqltest supports the following options:

  • --help, -?

    Display a help message and exit.

  • --async-client

    Enable asynchronous communication support in mysql protocol.

  • --basedir=dir_name, -b dir_name

    The base directory for tests.

  • --character-sets-dir=path

    The directory where character sets are installed.

  • --colored-diff

    Colorize the diff part of the output.

    If enabled, mysqltest uses diff command with --color='always' option to print the colored diff. If the command fails or is not supported, mysqltest will report an error and abort the test run.

    --color option for diff command is available from GNU diffutils version 3.4.
  • --compress, -C

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

  • --cursor-protocol

    Use cursors for prepared statements.

  • --database=db_name, -D db_name

    The default database to use.

  • --debug[=debug_options], -#[debug_options]

    Write a debugging log if MySQL is built with debugging support. The default debug_options value is 'd:t:S:i:O,/tmp/mysqltest.trace'.

  • --debug-check

    Print some debugging information when the program exits.

  • --debug-info

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

  • --default-character-set=charset_name

    Use charset_name as the default character set for the client and connection. For more information, see Connection Character Sets and Collations.

  • --explain-protocol


  • --host=host_name, -h host_name

    Connect to the MySQL server on the given host.

  • --include=file_name, -i file_name

    Include the contents of the given file before processing the contents of the test file. The included file should have the same format as other mysqltest test files. This option has the same effect as putting a --source file_name command as the first line of the test file.

  • --init-command=str

    SQL statement passed as an argument, to execute after connecting to the MYSQL server. If auto-reconnect is enabled, the statement is executed again after reconnection occurs.

  • --json-explain-protocol

    Run EXPLAIN EXTENDED on all SELECT, INSERT, REPLACE, UPDATE and DELETE queries. The json-explain-protocol

  • --logdir=dir_name

    The directory to use for log files.

  • --mark-progress

    Write the line number and elapsed time to test_file.progress.

  • --max-connect-retries=num

    The maximum number of connection attempts when connecting to server.

  • --max-connections=num

    The maximum number of simultaneous server connections per client (that is, per test). If not set, the maximum is 128. Minimum allowed limit is 8, maximum is 5120.

  • --no-defaults

    Do not read default options from any option files. If used, this must be the first option.

  • --plugin-dir=path

    The directory in which to look for plugins. It may be necessary to specify this option if the default_auth argument is used for the connect() command to specify an authentication plugin but mysqltest does not find it.

  • --password[=password], -p[password]

    The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, you are prompted for one.

  • --port=port_num, -P port_num

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

  • --protocol={TCP|SOCKET|PIPE|MEMORY}

    Choose the protocol for communication with the server. SOCKET is default.

  • --ps-protocol

    Use the prepared-statement protocol for communication.

  • --quiet

    Suppress all normal output. This is a synonym for --silent.

  • --record, -r

    Record the output that results from running the test file into the file named by the --result-file option, if that option is given. It is an error to use this option without also using --result-file.

  • --result-file=file_name, -R file_name

    This option specifies the file for test case expected results. --result-file, together with --record, determines how mysqltest treats the test actual and expected results for a test case:

    • If the test produces no results, mysqltest exits with an error message to that effect, unless --result-file is given and the named file is an empty file.

    • Otherwise, if --result-file is not given, mysqltest sends test results to the standard output.

    • With --result-file but not --record, mysqltest reads the expected results from the given file and compares them with the actual results. If the results do not match, mysqltest writes a .reject file in the log directory, outputs a diff of the two files, and exits with an error.

    • With both --result-file and --record, mysqltest updates the given file by writing the actual test results to it.

  • --server-public-key-path=file_name

    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 sha256_password 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 sha256_password plugin, including how to get the RSA public key, see The SHA-256 Authentication Plugin.

  • --silent, -s

    Suppress all normal output.

  • --skip-safemalloc

    Do not use memory allocation checking.

  • --socket=path, -S path

    The socket file to use when connecting to localhost (which is the default host).

  • --sp-protocol

    Execute DML statements within a stored procedure. For every DML statement, mysqltest creates and invokes a stored procedure that executes the statement rather than executing the statement directly.

  • --tail-lines=n

    Specify how many lines of the result to include in the output if the test fails because an SQL statement fails. The default is 0, meaning no lines of result printed.

  • --test-file=file_name, -x file_name

    Read test input from this file. The default is to read from the standard input.

  • --timer-file=file_name, -m file_name

    If given, the number of millisecond spent running the test will be written to this file. This is used by for its reporting.

  • --tls-version=protocol_list

    The protocols permitted by the client for encrypted connections. The value is a comma-separated list containing one or more of these protocols: TLSv1, TLSv1.1, TLSv1.2.

  • --tmpdir=dir_name, -t dir_name

    The temporary directory where socket files are created.

  • --trace-exec

    If enabled, this option causes mysqltest to immediately display the output from executed programs to stdout.

  • --user=user_name, -u user_name

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

  • --verbose, -v

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

  • --version, -V

    Display version information and exit.

  • --view-protocol

    Every SELECT statement is wrapped inside a view.