Menu:
mysqldumpslow:: mysqldumpslow -- Summarize Slow Query Log Files
This section describes administrative programs and programs that perform miscellaneous utility operations.
File: manual.info.tmp, Node: innochecksum, Next: myisam-ftdump, Prev: programs-admin-utils, Up: programs-admin-utils
*note 'innochecksum': innochecksum. prints checksums for 'InnoDB' files. This tool reads an 'InnoDB' 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 cause 'InnoDB' to deliberately shut down a running server, it may be preferable to use this tool rather than waiting for an in-production server to encounter the damaged pages.
note 'innochecksum': innochecksum. cannot be used on tablespace files that the server already has open. For such files, you should use note 'CHECK TABLE': check-table. to check tables within the tablespace. Attempting to run *note 'innochecksum': innochecksum. on a tablespace that the server already has open results in an 'Unable to lock file' error.
If checksum mismatches are found, restore the tablespace from backup or start the server and attempt to use *note 'mysqldump': mysqldump. to make a backup of the tables within the tablespace.
Invoke *note 'innochecksum': innochecksum. like this:
innochecksum [OPTIONS] FILE_NAME
innochecksum Options
*note 'innochecksum': innochecksum. supports the following options. For options that refer to page numbers, the numbers are zero-based.
'--help', '-?'
Command-Line Format
'--help'
Type
Boolean
Default Value
'false'
Displays command line help. Example usage:
innochecksum --help
'--info', '-I'
Command-Line Format
'--info'
Type
Boolean
Default Value
'false'
Synonym for '--help'. Displays command line help. Example usage:
innochecksum --info
'--version', '-V'
Command-Line Format
'--version'
Type
Boolean
Default Value
'false'
Displays version information. Example usage:
innochecksum --version
'--verbose', '-v'
Command-Line Format
'--verbose'
Type
Boolean
Default Value
'false'
Verbose mode; prints a progress indicator to the log file every five seconds. In order for the progress indicator to be printed, the log file must be specified using the '--log option'. To turn on 'verbose' mode, run:
innochecksum --verbose
To turn off verbose mode, run:
innochecksum --verbose=FALSE
The '--verbose' option and '--log' option can be specified at the same time. For example:
innochecksum --verbose --log=/var/lib/mysql/test/logtest.txt
To locate the progress indicator information in the log file, you can perform the following search:
cat ./logtest.txt | grep -i "okay"
The progress indicator information in the log file appears similar to the following:
page 1663 okay: 2.863% done
page 8447 okay: 14.537% done
page 13695 okay: 23.568% done
page 18815 okay: 32.379% done
page 23039 okay: 39.648% done
page 28351 okay: 48.789% done
page 33023 okay: 56.828% done
page 37951 okay: 65.308% done
page 44095 okay: 75.881% done
page 49407 okay: 85.022% done
page 54463 okay: 93.722% done
...
'--count', '-c'
Command-Line Format
'--count'
Type
Base name
Default Value
'true'
Print a count of the number of pages in the file and exit. Example usage:
innochecksum --count ../data/test/tab1.ibd
'--start-page=NUM', '-s NUM'
Command-Line Format
'--start-page=#'
Type
Numeric
Default Value
'0'
Start at this page number. Example usage:
innochecksum --start-page=600 ../data/test/tab1.ibd
or:
innochecksum -s 600 ../data/test/tab1.ibd
'--end-page=NUM', '-e NUM'
Command-Line Format
'--end-page=#'
Type
Numeric
Default Value
'0'
Minimum Value
'0'
Maximum Value
'18446744073709551615'
End at this page number. Example usage:
innochecksum --end-page=700 ../data/test/tab1.ibd
or:
innochecksum --p 700 ../data/test/tab1.ibd
'--page=NUM', '-p NUM'
Command-Line Format
'--page=#'
Type
Integer
Default Value
'0'
Check only this page number. Example usage:
innochecksum --page=701 ../data/test/tab1.ibd
'--strict-check', '-C'
Command-Line Format
'--strict-check=algorithm'
Type
Enumeration
Default Value
'crc32'
Valid Values
'innodb' 'crc32' 'none'
Specify a strict checksum algorithm. Options include 'innodb', 'crc32', and 'none'.
In this example, the 'innodb' checksum algorithm is specified:
innochecksum --strict-check=innodb ../data/test/tab1.ibd
In this example, the 'crc32' checksum algorithm is specified:
innochecksum -C crc32 ../data/test/tab1.ibd
The following conditions apply:
* If you do not specify the '--strict-check' option, *note
'innochecksum': innochecksum. validates against 'innodb',
'crc32' and 'none'.
* If you specify the 'none' option, only checksums generated by
'none' are allowed.
* If you specify the 'innodb' option, only checksums generated
by 'innodb' are allowed.
* If you specify the 'crc32' option, only checksums generated by
'crc32' are allowed.
'--no-check', '-n'
Command-Line Format
'--no-check'
Type
Boolean
Default Value
'false'
Ignore the checksum verification when rewriting a checksum. This option may only be used with the note 'innochecksum': innochecksum. '--write' option. If the '--write' option is not specified, note 'innochecksum': innochecksum. terminates.
In this example, an 'innodb' checksum is rewritten to replace an invalid checksum:
innochecksum --no-check --write innodb ../data/test/tab1.ibd
'--allow-mismatches', '-a'
Command-Line Format
'--allow-mismatches=#'
Type
Integer
Default Value
'0'
Minimum Value
'0'
Maximum Value
'18446744073709551615'
The maximum number of checksum mismatches allowed before *note 'innochecksum': innochecksum. terminates. The default setting isIn this example, an existing 'innodb' checksum is rewritten to set '--allow-mismatches' to 1.
innochecksum --allow-mismatches=1 --write innodb ../data/test/tab1.ibd
With '--allow-mismatches' set to 1, if there is a mismatch at page 600 and another at page 700 on a file with 1000 pages, the checksum is updated for pages 0-599 and 601-699. Because '--allow-mismatches' is set to 1, the checksum tolerates the first mismatch and terminates on the second mismatch, leaving page 600 and pages 700-999 unchanged.
'--write=NAME', '-w NUM'
Command-Line Format
'--write=algorithm'
Type
Enumeration
Default Value
'crc32'
Valid Values
'innodb' 'crc32' 'none'
Rewrite a checksum. When rewriting an invalid checksum, the '--no-check' option must be used together with the '--write' option. The '--no-check' option tells *note 'innochecksum': innochecksum. to ignore verification of the invalid checksum. You do not have to specify the '--no-check' option if the current checksum is valid.
An algorithm must be specified when using the '--write' option. Possible values for the '--write' option are:
* 'innodb': A checksum calculated in software, using the
original algorithm from 'InnoDB'.
* 'crc32': A checksum calculated using the 'crc32' algorithm,
possibly done with a hardware assist.
* 'none': A constant number.
The '--write' option rewrites entire pages to disk. If the new checksum is identical to the existing checksum, the new checksum is not written to disk in order to minimize I/O.
*note 'innochecksum': innochecksum. obtains an exclusive lock when the '--write' option is used.
In this example, a 'crc32' checksum is written for 'tab1.ibd':
innochecksum -w crc32 ../data/test/tab1.ibd
In this example, a 'crc32' checksum is rewritten to replace an invalid 'crc32' checksum:
innochecksum --no-check --write crc32 ../data/test/tab1.ibd
'--page-type-summary', '-S'
Command-Line Format
'--page-type-summary'
Type
Boolean
Default Value
'false'
Display a count of each page type in a tablespace. Example usage:
innochecksum --page-type-summary ../data/test/tab1.ibd
Sample output for '--page-type-summary':
File::../data/test/tab1.ibd
================PAGE TYPE SUMMARY==============
#PAGE_COUNT PAGE_TYPE
===============================================
2 Index page
0 Undo log page
1 Inode page
0 Insert buffer free list page
2 Freshly allocated page
1 Insert buffer bitmap
0 System page
0 Transaction system page
1 File Space Header
0 Extent descriptor page
0 BLOB page
0 Compressed BLOB page
0 Other type of page
===============================================
Additional information:
Undo page type: 0 insert, 0 update, 0 other
Undo page state: 0 active, 0 cached, 0 to_free, 0 to_purge, 0 prepared, 0 other
'--page-type-dump', '-D'
Command-Line Format
'--page-type-dump=name'
Type
String
Default Value
'[none]'
Dump the page type information for each page in a tablespace to 'stderr' or 'stdout'. Example usage:
innochecksum --page-type-dump=/tmp/a.txt ../data/test/tab1.ibd
'--log', '-l'
Command-Line Format
'--log=path'
Type
File name
Default Value
'[none]'
Log output for the *note 'innochecksum': innochecksum. tool. A log file name must be provided. Log output contains checksum values for each tablespace page. For uncompressed tables, LSN values are also provided. The '--log' replaces the '--debug' option, which was available in earlier releases. Example usage:
innochecksum --log=/tmp/log.txt ../data/test/tab1.ibd
or:
innochecksum -l /tmp/log.txt ../data/test/tab1.ibd
'-' option.
Specify the '-' option to read from standard input. If the '-' option is missing when 'read from standard in' is expected, note 'innochecksum': innochecksum. prints note 'innochecksum': innochecksum. usage information indicating that the '-' option was omitted. Example usages:
cat t1.ibd | innochecksum -
In this example, *note 'innochecksum': innochecksum. writes the 'crc32' checksum algorithm to 'a.ibd' without changing the original 't1.ibd' file.
cat t1.ibd | innochecksum --write=crc32 - > a.ibd
Running innochecksum on Multiple User-defined Tablespace Files
The following examples demonstrate how to run *note 'innochecksum': innochecksum. on multiple user-defined tablespace files ('.ibd' files).
Run *note 'innochecksum': innochecksum. for all tablespace ('.ibd') files in the 'test' database:
innochecksum ./data/test/*.ibd
Run *note 'innochecksum': innochecksum. for all tablespace files ('.ibd' files) that have a file name starting with 't':
innochecksum ./data/test/t*.ibd
Run *note 'innochecksum': innochecksum. for all tablespace files ('.ibd' files) in the 'data' directory:
innochecksum ./data/*/*.ibd
Note:
Running note 'innochecksum': innochecksum. on multiple user-defined tablespace files is not supported on Windows operating systems, as Windows shells such as 'cmd.exe' do not support glob pattern expansion. On Windows systems, note 'innochecksum': innochecksum. must be run separately for each user-defined tablespace file. For example:
innochecksum.exe t1.ibd
innochecksum.exe t2.ibd
innochecksum.exe t3.ibd
Running innochecksum on Multiple System Tablespace Files
By default, there is only one 'InnoDB' system tablespace file ('ibdata1') but multiple files for the system tablespace can be defined using the 'innodb_data_file_path' option. In the following example, three files for the system tablespace are defined using the 'innodb_data_file_path' option: 'ibdata1', 'ibdata2', and 'ibdata3'.
./bin/mysqld --no-defaults --innodb-data-file-path="ibdata1:10M;ibdata2:10M;ibdata3:10M:autoextend"
The three files ('ibdata1', 'ibdata2', and 'ibdata3') form one logical system tablespace. To run note 'innochecksum': innochecksum. on multiple files that form one logical system tablespace, note 'innochecksum': innochecksum. requires the '-' option to read tablespace files in from standard input, which is equivalent to concatenating multiple files to create one single file. For the example provided above, the following *note 'innochecksum': innochecksum. command would be used:
cat ibdata* | innochecksum -
Refer to the *note 'innochecksum': innochecksum. options information for more information about the '-' option.
Note:
Running note 'innochecksum': innochecksum. on multiple files in the same tablespace is not supported on Windows operating systems, as Windows shells such as 'cmd.exe' do not support glob pattern expansion. On Windows systems, note 'innochecksum': innochecksum. must be run separately for each system tablespace file. For example:
innochecksum.exe ibdata1
innochecksum.exe ibdata2
innochecksum.exe ibdata3
File: manual.info.tmp, Node: myisam-ftdump, Next: myisamchk, Prev: innochecksum, Up: programs-admin-utils
note 'myisam_ftdump': myisam-ftdump. displays information about 'FULLTEXT' indexes in 'MyISAM' tables. It reads the 'MyISAM' index file directly, so it must be run on the server host where the table is located. Before using note 'myisam_ftdump': myisam-ftdump, be sure to issue a 'FLUSH TABLES' statement first if the server is running.
*note 'myisam_ftdump': myisam-ftdump. 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 *note 'myisam_ftdump': myisam-ftdump. like this:
myisam_ftdump [OPTIONS] TBL_NAME INDEX_NUM
The TBL_NAME argument should be the name of a 'MyISAM' table. You can also specify a table by naming its index file (the file with the '.MYI' suffix). If you do not invoke *note 'myisam_ftdump': myisam-ftdump. 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 'test' database contains a table named 'mytexttable' that has the following definition:
CREATE TABLE mytexttable
(
id INT NOT NULL,
txt TEXT NOT NULL,
PRIMARY KEY (id),
FULLTEXT (txt)
) ENGINE=MyISAM;
The index on 'id' is index 0 and the 'FULLTEXT' index on 'txt' is index 1. If your working directory is the 'test' database directory, invoke *note 'myisam_ftdump': myisam-ftdump. as follows:
myisam_ftdump mytexttable 1
If the path name to the 'test' database directory is '/usr/local/mysql/data/test', you can also specify the table name argument using that path name. This is useful if you do not invoke *note 'myisam_ftdump': myisam-ftdump. in the database directory:
myisam_ftdump /usr/local/mysql/data/test/mytexttable 1
You can use *note 'myisam_ftdump': myisam-ftdump. to generate a list of index entries in order of frequency of occurrence like this on Unix-like systems:
myisam_ftdump -c mytexttable 1 | sort -r
On Windows, use:
myisam_ftdump -c mytexttable 1 | sort /R
*note 'myisam_ftdump': myisam-ftdump. supports the following options:
'--help', '-h' '-?'
Command-Line Format
'--help'
Display a help message and exit.
'--count', '-c'
Command-Line Format
'--count'
Calculate per-word statistics (counts and global weights).
'--dump', '-d'
Command-Line Format
'--dump'
Dump the index, including data offsets and word weights.
'--length', '-l'
Command-Line Format
'--length'
Report the length distribution.
'--stats', '-s'
Command-Line Format
'--stats'
Report global index statistics. This is the default operation if no other operation is specified.
'--verbose', '-v'
Command-Line Format
'--verbose'
Verbose mode. Print more output about what the program does.
File: manual.info.tmp, Node: myisamchk, Next: myisamlog, Prev: myisam-ftdump, Up: programs-admin-utils
Menu:
myisamchk-memory:: myisamchk Memory Usage
The note 'myisamchk': myisamchk. utility gets information about your database tables or checks, repairs, or optimizes them. note 'myisamchk': myisamchk. works with 'MyISAM' tables (tables that have '.MYD' and '.MYI' files for storing data and indexes).
You can also use the note 'CHECK TABLE': check-table. and note 'REPAIR TABLE': repair-table. statements to check and repair 'MyISAM' tables. See note check-table::, and note repair-table::.
The use of *note 'myisamchk': myisamchk. with partitioned tables is not supported.
Caution:
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 *note 'myisamchk': myisamchk. like this:
myisamchk [OPTIONS] TBL_NAME ...
The OPTIONS specify what you want note 'myisamchk': myisamchk. to do. They are described in the following sections. You can also get a list of options by invoking note 'myisamchk --help': myisamchk.
With no options, note 'myisamchk': myisamchk. simply checks your table as the default operation. To get more information or to tell note 'myisamchk': myisamchk. to take corrective action, specify options as described in the following discussion.
TBL_NAME is the database table you want to check or repair. If you run note 'myisamchk': myisamchk. somewhere other than in the database directory, you must specify the path to the database directory, because note 'myisamchk': myisamchk. has no idea where the database is located. In fact, *note 'myisamchk': myisamchk. 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 note 'myisamchk': myisamchk. command line if you wish. You can also specify a table by naming its index file (the file with the '.MYI' suffix). This enables you to specify all tables in a directory by using the pattern '.MYI'. For example, if you are in a database directory, you can check all the 'MyISAM' tables in that directory like this:
myisamchk *.MYI
If you are not in the database directory, you can check all the tables there by specifying the path to the directory:
myisamchk /PATH/TO/DATABASE_DIR/*.MYI
You can even check all tables in all databases by specifying a wildcard with the path to the MySQL data directory:
myisamchk /PATH/TO/DATADIR/*/*.MYI
The recommended way to quickly check all 'MyISAM' tables is:
myisamchk --silent --fast /PATH/TO/DATADIR/*/*.MYI
If you want to check all 'MyISAM' tables and repair any that are corrupted, you can use the following command:
myisamchk --silent --force --fast --update-state \
--key_buffer_size=64M --myisam_sort_buffer_size=64M \
--read_buffer_size=1M --write_buffer_size=1M \
/PATH/TO/DATADIR/*/*.MYI
This command assumes that you have more than 64MB free. For more information about memory allocation with note 'myisamchk': myisamchk, see note myisamchk-memory::.
For additional information about using note 'myisamchk': myisamchk, see note myisam-table-maintenance::.
Important:
_You must ensure that no other program is using the tables while you are running *note 'myisamchk': myisamchk._. The most effective means of doing so is to shut down the MySQL server while running note 'myisamchk': myisamchk, or to lock all tables that note 'myisamchk': myisamchk. is being used on.
Otherwise, when you run *note 'myisamchk': myisamchk, it may display the following error message:
warning: clients are using or haven't closed the table properly
This means that you are trying to check a table that has been updated by another program (such as the *note 'mysqld': mysqld. 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 'MyISAM' tables.
If note 'mysqld': mysqld. is running, you must force it to flush any table modifications that are still buffered in memory by using 'FLUSH TABLES'. You should then ensure that no one is using the tables while you are running note 'myisamchk': myisamchk.
However, the easiest way to avoid this problem is to use note 'CHECK TABLE': check-table. instead of note 'myisamchk': myisamchk. to check tables. See *note check-table::.
note 'myisamchk': myisamchk. supports the following options, which can be specified on the command line or in the '[myisamchk]' group of an option file. For information about option files used by MySQL programs, see note option-files::.
myisamchk Options
Option Name Description
-analyze Analyze the distribution of key values
-backup Make a backup of the .MYD file as file_name-time.BAK
-block-search Find the record that a block at the given offset belongs to
-character-sets-dir Directory where character sets can be found
-check Check the table for errors
-check-only-changed Check only tables that have changed since the last check
-correct-checksum Correct the checksum information for the table
-data-file-length Maximum length of the data file (when re-creating data file when it is full)
-debug Write debugging log
-decode_bits Decode_bits
-defaults-extra-file Read named option file in addition to usual option files
-defaults-file Read only named option file
-defaults-group-suffix Option group suffix value
-description Print some descriptive information about the table
-extend-check Do very thorough table check or repair that tries to recover every possible row from the data file
-fast Check only tables that haven't been closed properly
-force Do a repair operation automatically if myisamchk finds any errors in the table
-force Overwrite old temporary files. For use with the -r or -o option
-ft_max_word_len Maximum word length for FULLTEXT indexes
-ft_min_word_len Minimum word length for FULLTEXT indexes
-ft_stopword_file Use stopwords from this file instead of built-in list
-HELP Display help message and exit
-help Display help message and exit
-information Print informational statistics about the table that is checked
-key_buffer_size Size of buffer used for index blocks for MyISAM tables
-keys-used A bit-value that indicates which indexes to update
-max-record-length Skip rows larger than the given length if myisamchk cannot allocate memory to hold them
-medium-check Do a check that is faster than an -extend-check operation
-myisam_block_size Block size to be used for MyISAM index pages
-myisam_sort_buffer_size The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
-no-defaults Read no option files
-parallel-recover Uses the same technique as -r and -n, but creates all the keys in parallel, using different threads (beta)
-print-defaults Print default options
-quick Achieve a faster repair by not modifying the data file
-read_buffer_size Each thread that does a sequential scan allocates a buffer of this size for each table it scans
-read-only Do not mark the table as checked
-recover Do a repair that can fix almost any problem except unique keys that aren't unique
-safe-recover 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
-set-auto-increment Force AUTO_INCREMENT numbering for new records to start at the given value
-set-collation Specify the collation to use for sorting table indexes
-silent Silent mode
-sort_buffer_size The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
-sort-index Sort the index tree blocks in high-low order
-sort_key_blocks sort_key_blocks
-sort-records Sort records according to a particular index
-sort-recover Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large
-stats_method Specifies how MyISAM index statistics collection code should treat NULLs
-tmpdir Directory to be used for storing temporary files
-unpack Unpack a table that was packed with myisampack
-update-state Store information in the .MYI file to indicate when the table was checked and whether the table crashed
-verbose Verbose mode
-version Display version information and exit
-wait Wait for locked table to be unlocked, instead of terminating
-write_buffer_size Write buffer size
File: manual.info.tmp, Node: myisamchk-general-options, Next: myisamchk-check-options, Prev: myisamchk, Up: myisamchk
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 *note 'myisamchk': myisamchk. The sections following this one describe options that pertain only to specific operations, such as table checking or repairing.
'--help', '-?'
Command-Line Format
'--help'
Display a help message and exit. Options are grouped by type of operation.
'--HELP', '-H'
Command-Line Format
'--HELP'
Display a help message and exit. Options are presented in a single list.
'--debug=DEBUG_OPTIONS', '-# DEBUG_OPTIONS'
Command-Line Format
'--debug[=debug_options]'
Type
String
Default Value
'd:t:o,/tmp/myisamchk.trace'
Write a debugging log. A typical DEBUG_OPTIONS string is 'd:t:o,FILE_NAME'. The default is 'd:t:o,/tmp/myisamchk.trace'.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--defaults-extra-file=FILE_NAME'
Command-Line Format
'--defaults-extra-file=file_name'
Type
File name
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, an error occurs. If FILE_NAME is not an absolute path name, it is interpreted relative to the current directory.
For additional information about this and other option-file options, see *note option-file-options::.
'--defaults-file=FILE_NAME'
Command-Line Format
'--defaults-file=file_name'
Type
File name
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. If FILE_NAME is not an absolute path name, it is interpreted relative to the current directory.
For additional information about this and other option-file options, see *note option-file-options::.
'--defaults-group-suffix=STR'
Command-Line Format
'--defaults-group-suffix=str'
Type
String
Read not only the usual option groups, but also groups with the usual names and a suffix of STR. For example, *note 'myisamchk': myisamchk. normally reads the '[myisamchk]' group. If this option is given as '--defaults-group-suffix=_other', *note 'myisamchk': myisamchk. also reads the '[myisamchk_other]' group.
For additional information about this and other option-file options, see *note option-file-options::.
'--no-defaults'
Command-Line Format
'--no-defaults'
Do not read any option files. If program startup fails due to reading unknown options from an option file, '--no-defaults' can be used to prevent them from being read.
The exception is that the '.mylogin.cnf' file is read in all cases, if it exists. This permits passwords to be specified in a safer way than on the command line even when '--no-defaults' is used. To create '.mylogin.cnf', use the note 'mysql_config_editor': mysql-config-editor. utility. See note mysql-config-editor::.
For additional information about this and other option-file options, see *note option-file-options::.
'--print-defaults'
Command-Line Format
'--print-defaults'
Print the program name and all options that it gets from option files.
For additional information about this and other option-file options, see *note option-file-options::.
'--silent', '-s'
Command-Line Format
'--silent'
Silent mode. Write output only when errors occur. You can use '-s' twice ('-ss') to make *note 'myisamchk': myisamchk. very silent.
'--verbose', '-v'
Command-Line Format
'--verbose'
Verbose mode. Print more information about what the program does. This can be used with '-d' and '-e'. Use '-v' multiple times ('-vv', '-vvv') for even more output.
'--version', '-V'
Command-Line Format
'--version'
Display version information and exit.
'--wait', '-w'
Command-Line Format
'--wait'
Type
Boolean
Default Value
'false'
Instead of terminating with an error if the table is locked, wait until the table is unlocked before continuing. If you are running note 'mysqld': mysqld. with external locking disabled, the table can be locked only by another note 'myisamchk': myisamchk. command.
You can also set the following variables by using '--VAR_NAME=VALUE' syntax:
Variable Default Value
'decode_bits' 9
'ft_max_word_len' version-dependent
'ft_min_word_len' 4
'ft_stopword_file' built-in list
'key_buffer_size' 523264
'myisam_block_size' 1024
'myisam_sort_key_blocks' 16
'read_buffer_size' 262136
'sort_buffer_size' 2097144
'sort_key_blocks' 16
'stats_method' nulls_unequal
'write_buffer_size' 262136
The possible note 'myisamchk': myisamchk. variables and their default values can be examined with note 'myisamchk --help': myisamchk.:
'myisam_sort_buffer_size' is used when the keys are repaired by sorting keys, which is the normal case when you use '--recover'. 'sort_buffer_size' is a deprecated synonym for 'myisam_sort_buffer_size'.
'key_buffer_size' is used when you are checking the table with '--extend-check' 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 '--safe-recover'.
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 note 'CHAR': char, note 'VARCHAR': char, or note 'TEXT': blob. 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 note 'myisamchk': myisamchk. to repair by sorting, you can use the '--sort-recover' 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 'key_buffer_size' and 'myisam_sort_buffer_size' 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.
'myisam_block_size' is the size used for index blocks.
'stats_method' influences how 'NULL' values are treated for index statistics collection when the '--analyze' option is given. It acts like the 'myisam_stats_method' system variable. For more information, see the description of 'myisam_stats_method' in note server-system-variables::, and note index-statistics::.
'ft_min_word_len' and 'ft_max_word_len' indicate the minimum and maximum word length for 'FULLTEXT' indexes on 'MyISAM' tables. 'ft_stopword_file' names the stopword file. These need to be set under the following circumstances.
If you use *note 'myisamchk': myisamchk. to perform an operation that modifies table indexes (such as repair or analyze), the 'FULLTEXT' 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 'MyISAM' 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 'ft_min_word_len', 'ft_max_word_len', and 'ft_stopword_file' values to note 'myisamchk': myisamchk. that you use for note 'mysqld': mysqld. For example, if you have set the minimum word length to 3, you can repair a table with *note 'myisamchk': myisamchk. like this:
myisamchk --recover --ft_min_word_len=3 TBL_NAME.MYI
To ensure that *note 'myisamchk': myisamchk. and the server use the same values for full-text parameters, you can place each one in both the '[mysqld]' and '[myisamchk]' sections of an option file:
[mysqld]
ft_min_word_len=3
[myisamchk]
ft_min_word_len=3
An alternative to using note 'myisamchk': myisamchk. is to use the note 'REPAIR TABLE': repair-table, note 'ANALYZE TABLE': analyze-table, note 'OPTIMIZE TABLE': optimize-table, or *note 'ALTER TABLE': alter-table. These statements are performed by the server, which knows the proper full-text parameter values to use.
File: manual.info.tmp, Node: myisamchk-check-options, Next: myisamchk-repair-options, Prev: myisamchk-general-options, Up: myisamchk
4.6.3.2 myisamchk Check Options ...............................
*note 'myisamchk': myisamchk. supports the following options for table checking operations:
'--check', '-c'
Command-Line Format
'--check'
Check the table for errors. This is the default operation if you specify no option that selects an operation type explicitly.
'--check-only-changed', '-C'
Command-Line Format
'--check-only-changed'
Check only tables that have changed since the last check.
'--extend-check', '-e'
Command-Line Format
'--extend-check'
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, note 'myisamchk': myisamchk. or note 'myisamchk --medium-check': myisamchk. should be able to determine whether there are any errors in the table.
If you are using '--extend-check' and have plenty of memory, setting the 'key_buffer_size' 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 *note myisamchk-table-info::.
'--fast', '-F'
Command-Line Format
'--fast'
Check only tables that haven't been closed properly.
'--force', '-f'
Command-Line Format
'--force'
Do a repair operation automatically if *note 'myisamchk': myisamchk. finds any errors in the table. The repair type is the same as that specified with the '--recover' or '-r' option.
'--information', '-i'
Command-Line Format
'--information'
Print informational statistics about the table that is checked.
'--medium-check', '-m'
Command-Line Format
'--medium-check'
Do a check that is faster than an '--extend-check' operation. This finds only 99.99% of all errors, which should be good enough in most cases.
'--read-only', '-T'
Command-Line Format
'--read-only'
Do not mark the table as checked. This is useful if you use note 'myisamchk': myisamchk. to check a table that is in use by some other application that does not use locking, such as note 'mysqld': mysqld. when run with external locking disabled.
'--update-state', '-U'
Command-Line Format
'--update-state'
Store information in the '.MYI' file to indicate when the table was checked and whether the table crashed. This should be used to get full benefit of the '--check-only-changed' option, but you shouldn't use this option if the *note 'mysqld': mysqld. server is using the table and you are running it with external locking disabled.
File: manual.info.tmp, Node: myisamchk-repair-options, Next: myisamchk-other-options, Prev: myisamchk-check-options, Up: myisamchk
4.6.3.3 myisamchk Repair Options ................................
*note 'myisamchk': myisamchk. supports the following options for table repair operations (operations performed when an option such as '--recover' or '--safe-recover' is given):
'--backup', '-B'
Command-Line Format
'--backup'
Make a backup of the '.MYD' file as 'FILE_NAME-TIME.BAK'
'--character-sets-dir=DIR_NAME'
Command-Line Format
'--character-sets-dir=path'
Type
String
Default Value
'[none]'
The directory where character sets are installed. See *note charset-configuration::.
'--correct-checksum'
Command-Line Format
'--correct-checksum'
Correct the checksum information for the table.
'--data-file-length=LEN', '-D LEN'
Command-Line Format
'--data-file-length=len'
Type
Numeric
The maximum length of the data file (when re-creating data file when it is 'full').
'--extend-check', '-e'
Command-Line Format
'--extend-check'
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 *note myisamchk-table-info::.
'--force', '-f'
Command-Line Format
'--force'
Overwrite old intermediate files (files with names like 'TBL_NAME.TMD') instead of aborting.
'--keys-used=VAL', '-k VAL'
Command-Line Format
'--keys-used=val'
Type
Numeric
For note 'myisamchk': myisamchk, 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 note 'myisamchk -r': myisamchk.
'--max-record-length=LEN'
Command-Line Format
'--max-record-length=len'
Type
Numeric
Skip rows larger than the given length if *note 'myisamchk': myisamchk. cannot allocate memory to hold them.
'--parallel-recover', '-p'
Command-Line Format
'--parallel-recover'
Note:
This option is deprecated in MySQL 5.7.38 and removed in MySQL 5.7.39.
Use the same technique as '-r' and '-n', but create all the keys in parallel, using different threads. This is beta-quality code. Use at your own risk!
'--quick', '-q'
Command-Line Format
'--quick'
Achieve a faster repair by modifying only the index file, not the data file. You can specify this option twice to force *note 'myisamchk': myisamchk. to modify the original data file in case of duplicate keys.
'--recover', '-r'
Command-Line Format
'--recover'
Do a repair that can fix almost any problem except unique keys that are not unique (which is an extremely unlikely error with 'MyISAM' tables). If you want to recover a table, this is the option to try first. You should try '--safe-recover' only if *note 'myisamchk': myisamchk. reports that the table cannot be recovered using '--recover'. (In the unlikely case that '--recover' fails, the data file remains intact.)
If you have lots of memory, you should increase the value of 'myisam_sort_buffer_size'.
'--safe-recover', '-o'
Command-Line Format
'--safe-recover'
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 '--recover', but can handle a couple of very unlikely cases that '--recover' cannot. This recovery method also uses much less disk space than '--recover'. Normally, you should repair first using '--recover', and then with '--safe-recover' only if '--recover' fails.
If you have lots of memory, you should increase the value of 'key_buffer_size'.
'--set-collation=NAME'
Command-Line Format
'--set-collation=name'
Type
String
Specify the collation to use for sorting table indexes. The character set name is implied by the first part of the collation name.
'--sort-recover', '-n'
Command-Line Format
'--sort-recover'
Force *note 'myisamchk': myisamchk. to use sorting to resolve the keys even if the temporary files would be very large.
'--tmpdir=DIR_NAME', '-t DIR_NAME'
Command-Line Format
'--tmpdir=dir_name'
Type
Directory name
The path of the directory to be used for storing temporary files. If this is not set, *note 'myisamchk': myisamchk. uses the value of the 'TMPDIR' environment variable. '--tmpdir' 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 (':') on Unix and the semicolon (';') on Windows.
'--unpack', '-u'
Command-Line Format
'--unpack'
Unpack a table that was packed with *note 'myisampack': myisampack.
File: manual.info.tmp, Node: myisamchk-other-options, Next: myisamchk-table-info, Prev: myisamchk-repair-options, Up: myisamchk
4.6.3.4 Other myisamchk Options ...............................
*note 'myisamchk': myisamchk. supports the following options for actions other than table checks and repairs:
'--analyze', '-a'
Command-Line Format
'--analyze'
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 *note 'myisamchk --description --verbose TBL_NAME': myisamchk. command or the 'SHOW INDEX FROM TBL_NAME' statement.
'--block-search=OFFSET', '-b OFFSET'
Command-Line Format
'--block-search=offset'
Type
Numeric
Find the record that a block at the given offset belongs to.
'--description', '-d'
Command-Line Format
'--description'
Print some descriptive information about the table. Specifying the '--verbose' option once or twice produces additional information. See *note myisamchk-table-info::.
'--set-auto-increment[=VALUE]', '-A[VALUE]'
Force 'AUTO_INCREMENT' numbering for new records to start at the given value (or higher, if there are existing records with 'AUTO_INCREMENT' values this large). If VALUE is not specified, 'AUTO_INCREMENT' numbers for new records begin with the largest value currently in the table, plus one.
'--sort-index', '-S'
Command-Line Format
'--sort-index'
Sort the index tree blocks in high-low order. This optimizes seeks and makes table scans that use indexes faster.
'--sort-records=N', '-R N'
Command-Line Format
'--sort-records=#'
Type
Numeric
Sort records according to a particular index. This makes your data much more localized and may speed up range-based note 'SELECT': select. and 'ORDER BY' 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 note 'SHOW INDEX': show-index, which displays a table's indexes in the same order that *note 'myisamchk': myisamchk. sees them. Indexes are numbered beginning with 1.
If keys are not packed ('PACK_KEYS=0'), they have the same length, so when note 'myisamchk': myisamchk. sorts and moves records, it just overwrites record offsets in the index. If keys are packed ('PACK_KEYS=1'), note 'myisamchk': myisamchk. 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.)
File: manual.info.tmp, Node: myisamchk-table-info, Next: myisamchk-memory, Prev: myisamchk-other-options, Up: myisamchk
4.6.3.5 Obtaining Table Information with myisamchk ..................................................
To obtain a description of a 'MyISAM' table or statistics about it, use the commands shown here. The output from these commands is explained later in this section.
*note 'myisamchk -d TBL_NAME': myisamchk.
Runs note 'myisamchk': myisamchk. in 'describe mode' to produce a description of your table. If you start the MySQL server with external locking disabled, note 'myisamchk': myisamchk. may report an error for a table that is updated while it runs. However, because *note 'myisamchk': myisamchk. does not change the table in describe mode, there is no risk of destroying data.
*note 'myisamchk -dv TBL_NAME': myisamchk.
Adding '-v' runs *note 'myisamchk': myisamchk. in verbose mode so that it produces more information about the table. Adding '-v' a second time produces even more information.
*note 'myisamchk -eis TBL_NAME': myisamchk.
Shows only the most important information from a table. This operation is slow because it must read the entire table.
*note 'myisamchk -eiv TBL_NAME': myisamchk.
This is like '-eis', but tells you what is being done.
The TBL_NAME argument can be either the name of a 'MyISAM' table or the name of its index file, as described in *note myisamchk::. Multiple TBL_NAME arguments can be given.
Suppose that a table named 'person' has the following structure. (The 'MAX_ROWS' table option is included so that in the example output from *note 'myisamchk': myisamchk. shown later, some values are smaller and fit the output format more easily.)
CREATE TABLE person
(
id INT NOT NULL AUTO_INCREMENT,
last_name VARCHAR(20) NOT NULL,
first_name VARCHAR(20) NOT NULL,
birth DATE,
death DATE,
PRIMARY KEY (id),
INDEX (last_name, first_name),
INDEX (birth)
) MAX_ROWS = 1000000 ENGINE=MYISAM;
Suppose also that the table has these data and index file sizes:
-rw-rw---- 1 mysql mysql 9347072 Aug 19 11:47 person.MYD
-rw-rw---- 1 mysql mysql 6066176 Aug 19 11:47 person.MYI
Example of *note 'myisamchk -dvv': myisamchk. output:
MyISAM file: person
Record format: Packed
Character set: latin1_swedish_ci (8)
File-version: 1
Creation time: 2009-08-19 16:47:41
Recover time: 2009-08-19 16:47:56
Status: checked,analyzed,optimized keys
Auto increment key: 1 Last value: 306688
Data records: 306688 Deleted blocks: 0
Datafile parts: 306688 Deleted data: 0
Datafile pointer (bytes): 4 Keyfile pointer (bytes): 3
Datafile length: 9347072 Keyfile length: 6066176
Max datafile length: 4294967294 Max keyfile length: 17179868159
Recordlength: 54
table description:
Key Start Len Index Type Rec/key Root Blocksize
1 2 4 unique long 1 99328 1024
2 6 20 multip. varchar prefix 512 3563520 1024
27 20 varchar 512
3 48 3 multip. uint24 NULL 306688 6065152 1024
Field Start Length Nullpos Nullbit Type
1 1 1
2 2 4 no zeros
3 6 21 varchar
4 27 21 varchar
5 48 3 1 1 no zeros
6 51 3 1 2 no zeros
Explanations for the types of information *note 'myisamchk': myisamchk. 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:
'MyISAM file'
Name of the 'MyISAM' (index) file.
'Record format'
The format used to store table rows. The preceding examples use 'Fixed length'. Other possible values are 'Compressed' and 'Packed'. ('Packed' corresponds to what 'SHOW TABLE STATUS' reports as 'Dynamic'.)
'Chararacter set'
The table default character set.
'File-version'
Version of 'MyISAM' format. Always 1.
'Creation time'
When the data file was created.
'Recover time'
When the index/data file was last reconstructed.
'Status'
Table status flags. Possible values are 'crashed', 'open', 'changed', 'analyzed', 'optimized keys', and 'sorted index pages'.
'Auto increment key', 'Last value'
The key number associated the table's 'AUTO_INCREMENT' column, and the most recently generated value for this column. These fields do not appear if there is no such column.
'Data records'
The number of rows in the table.
'Deleted blocks'
How many deleted blocks still have reserved space. You can optimize your table to minimize this space. See *note myisam-optimization::.
'Datafile parts'
For dynamic-row format, this indicates how many data blocks there are. For an optimized table without fragmented rows, this is the same as 'Data records'.
'Deleted data'
How many bytes of unreclaimed deleted data there are. You can optimize your table to minimize this space. See *note myisam-optimization::.
'Datafile pointer'
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.
'Keyfile pointer'
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.
'Max datafile length'
How long the table data file can become, in bytes.
'Max keyfile length'
How long the table index file can become, in bytes.
'Recordlength'
How much space each row takes, in bytes.
The 'table description' part of the output includes a list of all keys in the table. For each key, *note 'myisamchk': myisamchk. displays some low-level information:
'Key'
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 'table description' lines for the second index. This indicates that it is a multiple-part index with two parts.
'Start'
Where in the row this portion of the index starts.
'Len'
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 'Len' values for all key parts.
'Index'
Whether a key value can exist multiple times in the index. Possible values are 'unique' or 'multip.' (multiple).
'Type'
What data type this portion of the index has. This is a 'MyISAM' data type with the possible values 'packed', 'stripped', or 'empty'.
'Root'
Address of the root index block.
'Blocksize'
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.
'Rec/key'
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 *note 'myisamchk -a': myisamchk. 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:
'Field'
The column number.
'Start'
The byte position of the column within table rows.
'Length'
The length of the column in bytes.
'Nullpos', 'Nullbit'
For columns that can be 'NULL', 'MyISAM' stores 'NULL' 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 'Nullpos' and 'Nullbit' values, if nonempty, indicate which byte and bit contains that flag indicating whether the column is 'NULL'.
The position and number of bytes used to store 'NULL' flags is shown in the line for field 1. This is why there are six 'Field' lines for the 'person' table even though it has only five columns.
'Type'
The data type. The value may contain any of the following descriptors:
* 'constant'
All rows have the same value.
* 'no endspace'
Do not store endspace.
* 'no endspace, not_always'
Do not store endspace and do not do endspace compression for
all values.
* 'no endspace, no empty'
Do not store endspace. Do not store empty values.
* 'table-lookup'
The column was converted to an *note 'ENUM': enum.
* 'zerofill(N)'
The most significant N bytes in the value are always 0 and are
not stored.
* 'no zeros'
Do not store zeros.
* 'always zero'
Zero values are stored using one bit.
'Huff tree'
The number of the Huffman tree associated with the column.
'Bits'
The number of bits used in the Huffman tree.
The 'Huff tree' and 'Bits' fields are displayed if the table has been compressed with note 'myisampack': myisampack. See note myisampack::, for an example of this information.
Example of *note 'myisamchk -eiv': myisamchk. output:
Checking MyISAM file: person
Data records: 306688 Deleted blocks: 0
- check file-size
- check record delete-chain
No recordlinks
- check key delete-chain
block_size 1024:
- check index reference
- check data record references index: 1
Key: 1: Keyblocks used: 98% Packed: 0% Max levels: 3
- check data record references index: 2
Key: 2: Keyblocks used: 99% Packed: 97% Max levels: 3
- check data record references index: 3
Key: 3: Keyblocks used: 98% Packed: -14% Max levels: 3
Total: Keyblocks used: 98% Packed: 89%
- check records and index references
*** LOTS OF ROW NUMBERS DELETED ***
Records: 306688 M.recordlength: 25 Packed: 83%
Recordspace used: 97% Empty space: 2% Blocks/Record: 1.00
Record blocks: 306688 Delete blocks: 0
Record data: 7934464 Deleted data: 0
Lost space: 256512 Linkdata: 1156096
User time 43.08, System time 1.68
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 0, Physical pagefaults 0, Swaps 0
Blocks in 0 out 7, Messages in 0 out 0, Signals 0
Voluntary context switches 0, Involuntary context switches 0
Maximum memory usage: 1046926 bytes (1023k)
*note 'myisamchk -eiv': myisamchk. output includes the following information:
'Data records'
The number of rows in the table.
'Deleted blocks'
How many deleted blocks still have reserved space. You can optimize your table to minimize this space. See *note myisam-optimization::.
'Key'
The key number.
'Keyblocks used'
What percentage of the keyblocks are used. When a table has just been reorganized with *note 'myisamchk': myisamchk, the values are very high (very near theoretical maximum).
'Packed'
MySQL tries to pack key values that have a common suffix. This can only be used for indexes on note 'CHAR': char. and note 'VARCHAR': char. 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.
'Max levels'
How deep the B-tree for this key is. Large tables with long key values get high values.
'Records'
How many rows are in the table.
'M.recordlength'
The average row length. This is the exact row length for tables with fixed-length rows, because all rows have the same length.
'Packed'
MySQL strips spaces from the end of strings. The 'Packed' value indicates the percentage of savings achieved by doing this.
'Recordspace used'
What percentage of the data file is used.
'Empty space'
What percentage of the data file is unused.
'Blocks/Record'
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 *note myisam-optimization::.
'Recordblocks'
How many blocks (links) are used. For fixed-format tables, this is the same as the number of rows.
'Deleteblocks'
How many blocks (links) are deleted.
'Recorddata'
How many bytes in the data file are used.
'Deleted data'
How many bytes in the data file are deleted (unused).
'Lost space'
If a row is updated to a shorter length, some space is lost. This is the sum of all such losses, in bytes.
'Linkdata'
When the dynamic table format is used, row fragments are linked with pointers (4 to 7 bytes each). 'Linkdata' is the sum of the amount of storage used by all such pointers.
File: manual.info.tmp, Node: myisamchk-memory, Prev: myisamchk-table-info, Up: myisamchk
4.6.3.6 myisamchk Memory Usage ..............................
Memory allocation is important when you run note 'myisamchk': myisamchk. note 'myisamchk': myisamchk. uses no more memory than its memory-related variables are set to. If you are going to use note 'myisamchk': myisamchk. 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 note 'myisamchk': myisamchk. 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):
myisamchk --myisam_sort_buffer_size=256M \
--key_buffer_size=512M \
--read_buffer_size=64M \
--write_buffer_size=64M ...
Using '--myisam_sort_buffer_size=16M' is probably enough for most cases.
Be aware that note 'myisamchk': myisamchk. uses temporary files in 'TMPDIR'. If 'TMPDIR' points to a memory file system, out of memory errors can easily occur. If this happens, run note 'myisamchk': myisamchk. with the '--tmpdir=DIR_NAME' option to specify a directory located on a file system that has more space.
When performing repair operations, *note 'myisamchk': myisamchk. 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 '--quick'; 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 '--recover' or '--sort-recover' (but not when using '--safe-recover'), you need space on disk for sorting. This space is allocated in the temporary directory (specified by 'TMPDIR' or '--tmpdir=DIR_NAME'). The following formula yields the amount of space required:
(LARGEST_KEY + ROW_POINTER_LENGTH) * NUMBER_OF_ROWS * 2
You can check the length of the keys and the ROW_POINTER_LENGTH with note 'myisamchk -dv TBL_NAME': myisamchk. (see note myisamchk-table-info::). The ROW_POINTER_LENGTH and NUMBER_OF_ROWS values are the 'Datafile pointer' and 'Data records' values in the table description. To determine the LARGEST_KEY value, check the 'Key' lines in the table description. The 'Len' column indicates the number of bytes for each key part. For a multiple-column index, the key size is the sum of the 'Len' values for all key parts.
If you have a problem with disk space during repair, you can try '--safe-recover' instead of '--recover'.
File: manual.info.tmp, Node: myisamlog, Next: myisampack, Prev: myisamchk, Up: programs-admin-utils
*note 'myisamlog': myisamlog. processes the contents of a 'MyISAM' log file. To create such a file, start the server with a '--log-isam=log_file' option.
Invoke *note 'myisamlog': myisamlog. like this:
myisamlog [OPTIONS] [FILE_NAME [TBL_NAME] ...]
The default operation is update ('-u'). If a recovery is done ('-r'), all writes and possibly updates and deletes are done and errors are only counted. The default log file name is 'myisam.log' if no LOG_FILE argument is given. If tables are named on the command line, only those tables are updated.
*note 'myisamlog': myisamlog. supports the following options:
'-?', '-I'
Display a help message and exit.
'-c N'
Execute only N commands.
'-f N'
Specify the maximum number of open files.
'-F FILEPATH/'
Specify the file path with a trailing slash.
'-i'
Display extra information before exiting.
'-o OFFSET'
Specify the starting offset.
'-p N'
Remove N components from path.
'-r'
Perform a recovery operation.
'-R RECORD_POS_FILE RECORD_POS'
Specify record position file and record position.
'-u'
Perform an update operation.
'-v'
Verbose mode. Print more output about what the program does. This option can be given multiple times to produce more and more output.
'-w WRITE_FILE'
Specify the write file.
'-V'
Display version information.
File: manual.info.tmp, Node: myisampack, Next: mysql-config-editor, Prev: myisamlog, Up: programs-admin-utils
The note 'myisampack': myisampack. utility compresses 'MyISAM' tables. note 'myisampack': myisampack. works by compressing each column in the table separately. Usually, *note 'myisampack': myisampack. 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 'mmap()' when possible to perform memory mapping on compressed tables. If 'mmap()' does not work, MySQL falls back to normal read/write file operations.
Please note the following:
If the note 'mysqld': mysqld. server was invoked with external locking disabled, it is not a good idea to invoke note 'myisampack': myisampack. 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).
*note 'myisampack': myisampack. does not support partitioned tables.
Invoke *note 'myisampack': myisampack. like this:
myisampack [OPTIONS] FILE_NAME ...
Each file name argument should be the name of an index ('.MYI') file. If you are not in the database directory, you should specify the path name to the file. It is permissible to omit the '.MYI' extension.
After you compress a table with note 'myisampack': myisampack, use note 'myisamchk -rq': myisamchk. to rebuild its indexes. *note myisamchk::.
note 'myisampack': myisampack. supports the following options. It also reads option files and supports the options for processing them described at note option-file-options::.
'--help', '-?'
Command-Line Format
'--help'
Display a help message and exit.
'--backup', '-b'
Command-Line Format
'--backup'
Make a backup of each table's data file using the name 'TBL_NAME.OLD'.
'--character-sets-dir=DIR_NAME'
Command-Line Format
'--character-sets-dir=dir_name'
Type
Directory name
The directory where character sets are installed. See *note charset-configuration::.
'--debug[=DEBUG_OPTIONS]', '-# [DEBUG_OPTIONS]'
Command-Line Format
'--debug[=debug_options]'
Type
String
Default Value
'd:t:o'
Write a debugging log. A typical DEBUG_OPTIONS string is 'd:t:o,FILE_NAME'. The default is 'd:t:o'.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--force', '-f'
Command-Line Format
'--force'
Produce a packed table even if it becomes larger than the original or if the intermediate file from an earlier invocation of note 'myisampack': myisampack. exists. (note 'myisampack': myisampack. creates an intermediate file named 'TBL_NAME.TMD' in the database directory while it compresses the table. If you kill note 'myisampack': myisampack, the '.TMD' file might not be deleted.) Normally, note 'myisampack': myisampack. exits with an error if it finds that 'TBL_NAME.TMD' exists. With '--force', *note 'myisampack': myisampack. packs the table anyway.
'--join=BIG_TBL_NAME', '-j BIG_TBL_NAME'
Command-Line Format
'--join=big_tbl_name'
Type
String
Join all tables named on the command line into a single packed table BIG_TBL_NAME. All tables that are to be combined must have identical structure (same column names and types, same indexes, and so forth).
BIG_TBL_NAME must not exist prior to the join operation. All source tables named on the command line to be merged into BIG_TBL_NAME must exist. The source tables are read for the join operation but not modified.
'--silent', '-s'
Command-Line Format
'--silent'
Silent mode. Write output only when errors occur.
'--test', '-t'
Command-Line Format
'--test'
Do not actually pack the table, just test packing it.
'--tmpdir=DIR_NAME', '-T DIR_NAME'
Command-Line Format
'--tmpdir=dir_name'
Type
Directory name
Use the named directory as the location where *note 'myisampack': myisampack. creates temporary files.
'--verbose', '-v'
Command-Line Format
'--verbose'
Verbose mode. Write information about the progress of the packing operation and its result.
'--version', '-V'
Command-Line Format
'--version'
Display version information and exit.
'--wait', '-w'
Command-Line Format
'--wait'
Wait and retry if the table is in use. If the note 'mysqld': mysqld. server was invoked with external locking disabled, it is not a good idea to invoke note 'myisampack': myisampack. if the table might be updated by the server during the packing process.
The following sequence of commands illustrates a typical table compression session:
$> ls -l station.*
-rw-rw-r-- 1 jones my 994128 Apr 17 19:00 station.MYD
-rw-rw-r-- 1 jones my 53248 Apr 17 19:00 station.MYI
-rw-rw-r-- 1 jones my 5767 Apr 17 19:00 station.frm
$> myisamchk -dvv station
MyISAM file: station
Isam-version: 2
Creation time: 1996-03-13 10:08:58
Recover time: 1997-02-02 3:06:43
Data records: 1192 Deleted blocks: 0
Datafile parts: 1192 Deleted data: 0
Datafile pointer (bytes): 2 Keyfile pointer (bytes): 2
Max datafile length: 54657023 Max keyfile length: 33554431
Recordlength: 834
Record format: Fixed length
table description:
Key Start Len Index Type Root Blocksize Rec/key
1 2 4 unique unsigned long 1024 1024 1
2 32 30 multip. text 10240 1024 1
Field Start Length Type
1 1 1
2 2 4
3 6 4
4 10 1
5 11 20
6 31 1
7 32 30
8 62 35
9 97 35
10 132 35
11 167 4
12 171 16
13 187 35
14 222 4
15 226 16
16 242 20
17 262 20
18 282 20
19 302 30
20 332 4
21 336 4
22 340 1
23 341 8
24 349 8
25 357 8
26 365 2
27 367 2
28 369 4
29 373 4
30 377 1
31 378 2
32 380 8
33 388 4
34 392 4
35 396 4
36 400 4
37 404 1
38 405 4
39 409 4
40 413 4
41 417 4
42 421 4
43 425 4
44 429 20
45 449 30
46 479 1
47 480 1
48 481 79
49 560 79
50 639 79
51 718 79
52 797 8
53 805 1
54 806 1
55 807 20
56 827 4
57 831 4
$> myisampack station.MYI
Compressing station.MYI: (1192 records)
- Calculating statistics
normal: 20 empty-space: 16 empty-zero: 12 empty-fill: 11
pre-space: 0 end-space: 12 table-lookups: 5 zero: 7
Original trees: 57 After join: 17
- Compressing file
87.14%
Remember to run myisamchk -rq on compressed tables
$> myisamchk -rq station
- check record delete-chain
- recovering (with sort) MyISAM-table 'station'
Data records: 1192
- Fixing index 1
- Fixing index 2
$> mysqladmin -uroot flush-tables
$> ls -l station.*
-rw-rw-r-- 1 jones my 127874 Apr 17 19:00 station.MYD
-rw-rw-r-- 1 jones my 55296 Apr 17 19:04 station.MYI
-rw-rw-r-- 1 jones my 5767 Apr 17 19:00 station.frm
$> myisamchk -dvv station
MyISAM file: station
Isam-version: 2
Creation time: 1996-03-13 10:08:58
Recover time: 1997-04-17 19:04:26
Data records: 1192 Deleted blocks: 0
Datafile parts: 1192 Deleted data: 0
Datafile pointer (bytes): 3 Keyfile pointer (bytes): 1
Max datafile length: 16777215 Max keyfile length: 131071
Recordlength: 834
Record format: Compressed
table description:
Key Start Len Index Type Root Blocksize Rec/key
1 2 4 unique unsigned long 10240 1024 1
2 32 30 multip. text 54272 1024 1
Field Start Length Type Huff tree Bits
1 1 1 constant 1 0
2 2 4 zerofill(1) 2 9
3 6 4 no zeros, zerofill(1) 2 9
4 10 1 3 9
5 11 20 table-lookup 4 0
6 31 1 3 9
7 32 30 no endspace, not_always 5 9
8 62 35 no endspace, not_always, no empty 6 9
9 97 35 no empty 7 9
10 132 35 no endspace, not_always, no empty 6 9
11 167 4 zerofill(1) 2 9
12 171 16 no endspace, not_always, no empty 5 9
13 187 35 no endspace, not_always, no empty 6 9
14 222 4 zerofill(1) 2 9
15 226 16 no endspace, not_always, no empty 5 9
16 242 20 no endspace, not_always 8 9
17 262 20 no endspace, no empty 8 9
18 282 20 no endspace, no empty 5 9
19 302 30 no endspace, no empty 6 9
20 332 4 always zero 2 9
21 336 4 always zero 2 9
22 340 1 3 9
23 341 8 table-lookup 9 0
24 349 8 table-lookup 10 0
25 357 8 always zero 2 9
26 365 2 2 9
27 367 2 no zeros, zerofill(1) 2 9
28 369 4 no zeros, zerofill(1) 2 9
29 373 4 table-lookup 11 0
30 377 1 3 9
31 378 2 no zeros, zerofill(1) 2 9
32 380 8 no zeros 2 9
33 388 4 always zero 2 9
34 392 4 table-lookup 12 0
35 396 4 no zeros, zerofill(1) 13 9
36 400 4 no zeros, zerofill(1) 2 9
37 404 1 2 9
38 405 4 no zeros 2 9
39 409 4 always zero 2 9
40 413 4 no zeros 2 9
41 417 4 always zero 2 9
42 421 4 no zeros 2 9
43 425 4 always zero 2 9
44 429 20 no empty 3 9
45 449 30 no empty 3 9
46 479 1 14 4
47 480 1 14 4
48 481 79 no endspace, no empty 15 9
49 560 79 no empty 2 9
50 639 79 no empty 2 9
51 718 79 no endspace 16 9
52 797 8 no empty 2 9
53 805 1 17 1
54 806 1 3 9
55 807 20 no empty 3 9
56 827 4 no zeros, zerofill(2) 2 9
57 831 4 no zeros, zerofill(1) 2 9
*note 'myisampack': myisampack. displays the following kinds of information:
'normal'
The number of columns for which no extra packing is used.
'empty-space'
The number of columns containing values that are only spaces. These occupy one bit.
'empty-zero'
The number of columns containing values that are only binary zeros. These occupy one bit.
'empty-fill'
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 note 'BIGINT': integer-types. column (eight bytes) can be stored as a note 'TINYINT': integer-types. column (one byte) if all its values are in the range from '-128' to '127'.
'pre-space'
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.
'end-space'
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.
'table-lookup'
The column had only a small number of different values, which were converted to an *note 'ENUM': enum. before Huffman compression.
'zero'
The number of columns for which all values are zero.
'Original trees'
The initial number of Huffman trees.
'After join'
The number of distinct Huffman trees left after joining trees to save some header space.
After a table has been compressed, the 'Field' lines displayed by *note 'myisamchk -dvv': myisamchk. include additional information about each column:
'Type'
The data type. The value may contain any of the following descriptors:
* 'constant'
All rows have the same value.
* 'no endspace'
Do not store endspace.
* 'no endspace, not_always'
Do not store endspace and do not do endspace compression for
all values.
* 'no endspace, no empty'
Do not store endspace. Do not store empty values.
* 'table-lookup'
The column was converted to an *note 'ENUM': enum.
* 'zerofill(N)'
The most significant N bytes in the value are always 0 and are
not stored.
* 'no zeros'
Do not store zeros.
* 'always zero'
Zero values are stored using one bit.
'Huff tree'
The number of the Huffman tree associated with the column.
'Bits'
The number of bits used in the Huffman tree.
After you run note 'myisampack': myisampack, use note 'myisamchk': myisamchk. 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:
myisamchk -rq --sort-index --analyze TBL_NAME.MYI
After you have installed the packed table into the MySQL database directory, you should execute note 'mysqladmin flush-tables': mysqladmin. to force note 'mysqld': mysqld. to start using the new table.
To unpack a packed table, use the '--unpack' option to *note 'myisamchk': myisamchk.
File: manual.info.tmp, Node: mysql-config-editor, Next: mysqlbinlog, Prev: myisampack, Up: programs-admin-utils
The *note 'mysql_config_editor': mysql-config-editor. utility enables you to store authentication credentials in an obfuscated login path file named '.mylogin.cnf'. The file location is the '%APPDATA%' 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.
The unobfuscated format of the '.mylogin.cnf' login path file consists of option groups, similar to other option files. Each option group in '.mylogin.cnf' is called a 'login path,' which is a group that permits only certain options: 'host', 'user', 'password', 'port' and 'socket'. Think of a login path option group as a set of options that specify which MySQL server to connect to and which account to authenticate as. Here is an unobfuscated example:
[client]
user = mydefaultname
password = mydefaultpass
host = 127.0.0.1
[mypath]
user = myothername
password = myotherpass
host = localhost
When you invoke a client program to connect to the server, the client uses '.mylogin.cnf' 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 *note option-files::.
To specify an alternate login path file name, set the 'MYSQL_TEST_LOGIN_FILE' environment variable. This variable is recognized by note 'mysql_config_editor': mysql-config-editor, by standard MySQL clients (note 'mysql': mysql, *note 'mysqladmin': mysqladmin, and so forth), and by the 'mysql-test-run.pl' testing utility.
Programs use groups in the login path file as follows:
*note 'mysql_config_editor': mysql-config-editor. operates on the 'client' login path by default if you specify no '--login-path=NAME' option to indicate explicitly which login path to use.
Without a '--login-path' option, client programs read the same option groups from the login path file that they read from other option files. Consider this command:
mysql
By default, the *note 'mysql': mysql. client reads the '[client]' and '[mysql]' groups from other option files, so it reads them from the login path file as well.
With a '--login-path' option, client programs additionally read the named login path from the login path file. The option groups read from other option files remain the same. Consider this command:
mysql --login-path=mypath
The *note 'mysql': mysql. client reads '[client]' and '[mysql]' from other option files, and '[client]', '[mysql]', and '[mypath]' from the login path file.
Client programs read the login path file even when the '--no-defaults' option is used, unless '--no-login-paths' (https://dev.mysql.com/doc/refman/8.4/en/option-file-options.html#option_general_no-login-paths) is set. This permits passwords to be specified in a safer way than on the command line even if '--no-defaults' is present.
note 'mysql_config_editor': mysql-config-editor. obfuscates the '.mylogin.cnf' file so it cannot be read as cleartext, and its contents when unobfuscated 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. note 'mysql_config_editor': mysql-config-editor. provides a 'print' command for displaying the login path 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 obfuscation used by *note 'mysql_config_editor': mysql-config-editor. prevents passwords from appearing in '.mylogin.cnf' as cleartext and provides a measure of security by preventing inadvertent password exposure. For example, if you display a regular unobfuscated 'my.cnf' option file on the screen, any passwords it contains are visible for anyone to see. With '.mylogin.cnf', that is not true, but the obfuscation used is not likely to 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 unobfuscate the '.mylogin.cnf' file with some effort.
The login path file must be readable and writable to the current user, and inaccessible to other users. Otherwise, *note 'mysql_config_editor': mysql-config-editor. ignores it, and client programs do not use it, either.
Invoke *note 'mysql_config_editor': mysql-config-editor. like this:
mysql_config_editor [PROGRAM_OPTIONS] COMMAND [COMMAND_OPTIONS]
If the login path file does not exist, *note 'mysql_config_editor': mysql-config-editor. creates it.
Command arguments are given as follows:
PROGRAM_OPTIONS consists of general *note 'mysql_config_editor': mysql-config-editor. options.
'command' indicates what action to perform on the '.mylogin.cnf' login path file. For example, 'set' writes a login path to the file, 'remove' removes a login path, and 'print' displays login path contents.
COMMAND_OPTIONS indicates any additional options specific 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:
mysql_config_editor --help set
mysql_config_editor set --help
The first command line displays a general *note 'mysql_config_editor': mysql-config-editor. help message, and ignores the 'set' command. The second command line displays a help message specific to the 'set' command.
Suppose that you want to establish a 'client' login path that defines your default connection parameters, and an additional login path named 'remote' for connecting to the MySQL server the host 'remote.example.com'. You want to log in as follows:
By default, to the local server with a user name and password of 'localuser' and 'localpass'
To the remote server with a user name and password of 'remoteuser' and 'remotepass'
To set up the login paths in the '.mylogin.cnf' file, use the following 'set' commands. Enter each command on a single line, and enter the appropriate passwords when prompted:
$> mysql_config_editor set --login-path=client
--host=localhost --user=localuser --password
Enter password: ENTER PASSWORD "LOCALPASS" HERE
$> mysql_config_editor set --login-path=remote
--host=remote.example.com --user=remoteuser --password
Enter password: ENTER PASSWORD "REMOTEPASS" HERE
*note 'mysql_config_editor': mysql-config-editor. uses the 'client' login path by default, so the '--login-path=client' option can be omitted from the first command without changing its effect.
To see what *note 'mysql_config_editor': mysql-config-editor. writes to the '.mylogin.cnf' file, use the 'print' command:
$> mysql_config_editor print --all
[client]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com
The 'print' 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 cleartext.
If you do not specify '--all' to display all login paths or '--login-path=NAME' to display a named login path, the 'print' command displays the 'client' login path by default, if there is one.
As shown by the preceding example, the login path file can contain multiple login paths. In this way, *note 'mysql_config_editor': mysql-config-editor. makes it easy to set up multiple 'personalities' for connecting to different MySQL servers, or for connecting to a given server using different accounts. Any of these can be selected by name later using the '--login-path' option when you invoke a client program. For example, to connect to the remote server, use this command:
mysql --login-path=remote
Here, *note 'mysql': mysql. reads the '[client]' and '[mysql]' option groups from other option files, and the '[client]', '[mysql]', and '[remote]' groups from the login path file.
To connect to the local server, use this command:
mysql --login-path=client
Because *note 'mysql': mysql. reads the 'client' and 'mysql' login paths by default, the '--login-path' option does not add anything in this case. That command is equivalent to this one:
mysql
Options read from the login path file take precedence over options read from other option files. Options read from login path groups appearing later in the login path file take precedence over options read from groups appearing earlier in the file.
note 'mysql_config_editor': mysql-config-editor. adds login paths to the login path file in the order you create them, so you should create more general login paths first and more specific paths later. If you need to move a login path within the file, you can remove it, then recreate it to add it to the end. For example, a 'client' login path is more general because it is read by all client programs, whereas a 'mysqldump' login path is read only by note 'mysqldump': mysqldump. Options specified later override options specified earlier, so putting the login paths in the order 'client', 'mysqldump' enables *note 'mysqldump': mysqldump.-specific options to override 'client' options.
When you use the 'set' command with *note 'mysql_config_editor': mysql-config-editor. to create a login path, you need not specify all possible option values (host name, user name, password, port, socket). 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. Any options specified on the command line override those specified in the login path file or other option files. For example, if the credentials in the 'remote' login path also apply for the host 'remote2.example.com', connect to the server on that host like this:
mysql --login-path=remote --host=remote2.example.com
mysql_config_editor General Options
note 'mysql_config_editor': mysql-config-editor. supports the following general options, which may be used preceding any command named on the command line. For descriptions of command-specific options, see note mysql-config-editor-commands::.
mysql_config_editor General Options
Option Name Description
-debug Write debugging log
-help Display help message and exit
-verbose Verbose mode
-version Display version information and exit
'--help', '-?'
Command-Line Format
'--help'
Display a general help message and exit.
To see a command-specific help message, invoke *note 'mysql_config_editor': mysql-config-editor. as follows, where COMMAND is a command other than 'help':
mysql_config_editor COMMAND --help
'--debug[=DEBUG_OPTIONS]', '-# DEBUG_OPTIONS'
Command-Line Format
'--debug[=debug_options]'
Type
String
Default Value
'd:t:o'
Write a debugging log. A typical DEBUG_OPTIONS string is 'd:t:o,FILE_NAME'. The default is 'd:t:o,/tmp/mysql_config_editor.trace'.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--verbose', '-v'
Command-Line Format
'--verbose'
Verbose mode. Print more information about what the program does. This option may be helpful in diagnosing problems if an operation does not have the effect you expect.
'--version', '-V'
Command-Line Format
'--version'
Display version information and exit.
mysql_config_editor Commands and Command-Specific Options
This section describes the permitted *note 'mysql_config_editor': mysql-config-editor. commands, and, for each one, the command-specific options permitted following the command name on the command line.
In addition, note 'mysql_config_editor': mysql-config-editor. supports general options that can be used preceding any command. For descriptions of these options, see note mysql-config-editor-command-options::.
*note 'mysql_config_editor': mysql-config-editor. supports these commands:
'help'
Display a general help message and exit. This command takes no following options.
To see a command-specific help message, invoke *note 'mysql_config_editor': mysql-config-editor. as follows, where COMMAND is a command other than 'help':
mysql_config_editor COMMAND --help
'print [OPTIONS]'
Print the contents of the login path file in unobfuscated form, with the exception that passwords are displayed as '*****'.
The default login path name is 'client' if no login path is named. If both '--all' and '--login-path' are given, '--all' takes precedence.
The 'print' command permits these options following the command name:
* '--help', '-?'
Display a help message for the 'print' command and exit.
To see a general help message, use *note 'mysql_config_editor
--help': mysql-config-editor.
* '--all'
Print the contents of all login paths in the login path file.
* '--login-path=NAME', '-G NAME'
Print the contents of the named login path.
'remove [OPTIONS]'
Remove a login path from the login path file, or modify a login path by removing options from it.
This command removes from the login path only such options as are specified with the '--host', '--password', '--port', '--socket', and '--user' options. If none of those options are given, 'remove' removes the entire login path. For example, this command removes only the 'user' option from the 'mypath' login path rather than the entire 'mypath' login path:
mysql_config_editor remove --login-path=mypath --user
This command removes the entire 'mypath' login path:
mysql_config_editor remove --login-path=mypath
The 'remove' command permits these options following the command name:
* '--help', '-?'
Display a help message for the 'remove' command and exit.
To see a general help message, use *note 'mysql_config_editor
--help': mysql-config-editor.
* '--host', '-h'
Remove the host name from the login path.
* '--login-path=NAME', '-G NAME'
The login path to remove or modify. The default login path
name is 'client' if this option is not given.
* '--password', '-p'
Remove the password from the login path.
* '--port', '-P'
Remove the TCP/IP port number from the login path.
* '--socket', '-S'
Remove the Unix socket file name from the login path.
* '--user', '-u'
Remove the user name from the login path.
* '--warn', '-w'
Warn and prompt the user for confirmation if the command
attempts to remove the default login path ('client') and
'--login-path=client' was not specified. This option is
enabled by default; use '--skip-warn' to disable it.
'reset [OPTIONS]'
Empty the contents of the login path file.
The 'reset' command permits these options following the command name:
* '--help', '-?'
Display a help message for the 'reset' command and exit.
To see a general help message, use *note 'mysql_config_editor
--help': mysql-config-editor.
'set [OPTIONS]'
Write a login path to the login path file.
This command writes to the login path only such options as are specified with the '--host', '--password', '--port', '--socket', and '--user' options. If none of those options are given, *note 'mysql_config_editor': mysql-config-editor. writes the login path as an empty group.
The 'set' command permits these options following the command name:
* '--help', '-?'
Display a help message for the 'set' command and exit.
To see a general help message, use *note 'mysql_config_editor
--help': mysql-config-editor.
* '--host=HOST_NAME', '-h HOST_NAME'
The host name to write to the login path.
* '--login-path=NAME', '-G NAME'
The login path to create. The default login path name is
'client' if this option is not given.
* '--password', '-p'
Prompt for a password to write to the login path. After *note
'mysql_config_editor': mysql-config-editor. displays the
prompt, type the password and press Enter. To prevent other
users from seeing the password, *note 'mysql_config_editor':
mysql-config-editor. does not echo it.
To specify an empty password, press Enter at the password
prompt. The resulting login path written to the login path
file includes a line like this:
password =
* '--port=PORT_NUM', '-P PORT_NUM'
The TCP/IP port number to write to the login path.
* '--socket=FILE_NAME', '-S FILE_NAME'
The Unix socket file name to write to the login path.
* '--user=USER_NAME', '-u USER_NAME'
The user name to write to the login path.
* '--warn', '-w'
Warn and prompt the user for confirmation if the command
attempts to overwrite an existing login path. This option is
enabled by default; use '--skip-warn' to disable it.
File: manual.info.tmp, Node: mysqlbinlog, Next: mysqldumpslow, Prev: mysql-config-editor, Up: programs-admin-utils
Menu:
mysqlbinlog-server-id:: Specifying the mysqlbinlog Server ID
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 note 'mysqlbinlog': mysqlbinlog. utility. You can also use note 'mysqlbinlog': mysqlbinlog. to display the contents of relay log files written by a replica 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 note binary-log::, and note replica-logs::.
Invoke *note 'mysqlbinlog': mysqlbinlog. like this:
mysqlbinlog [OPTIONS] LOG_FILE ...
For example, to display the contents of the binary log file named 'binlog.000003', use this command:
mysqlbinlog binlog.000003
The output includes events contained in 'binlog.000003'. 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 *note replication-formats::, for information about logging modes.
Events are preceded by header comments that provide additional information. For example:
# at 141
#100309 9:28:36 server id 123 end_log_pos 245
Query thread_id=3350 exec_time=11 error_code=0
In the first line, the number following 'at' indicates the file offset, or 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 replica servers. 'server id' is the 'server_id' value of the server where the event originated. 'end_log_pos' indicates where the next event starts (that is, it is the end position of the current event + 1). 'thread_id' indicates which thread executed the event. 'exec_time' is the time spent executing the event, on a replication source server. On a replica, it is the difference of the end execution time on the replica minus the beginning execution time on the source. The difference serves as an indicator of how much replication lags behind the source. 'error_code' indicates the result from executing the event. Zero means that no error occurred.
Note:
When using event groups, the file offsets of events may be grouped together and the comments of events may be grouped together. Do not mistake these grouped events for blank file offsets.
The output from note 'mysqlbinlog': mysqlbinlog. can be re-executed (for example, by using it as input to note 'mysql': mysql.) to redo the statements in the log. This is useful for recovery operations after an unexpected server exit. For other usage examples, see the discussion later in this section and in *note point-in-time-recovery::.
You can use *note 'mysqlbinlog': mysqlbinlog. to read binary log files directly and apply them to the local MySQL server. You can also read binary logs from a remote server by using the '--read-from-remote-server' option. To read remote binary logs, the connection parameter options can be given to indicate how to connect to the server. These options are '--host', '--password', '--port', '--protocol', '--socket', and '--user'.
When running note 'mysqlbinlog': mysqlbinlog. against a large binary log, be careful that the filesystem has enough space for the resulting files. To configure the directory that note 'mysqlbinlog': mysqlbinlog. uses for temporary files, use the 'TMPDIR' environment variable.
*note 'mysqlbinlog': mysqlbinlog. sets the value of 'pseudo_slave_mode' to true before executing any SQL statements. This system variable affects the handling of XA transactions.
note 'mysqlbinlog': mysqlbinlog. supports the following options, which can be specified on the command line or in the '[mysqlbinlog]' and '[client]' groups of an option file. For information about option files used by MySQL programs, see note option-files::.
mysqlbinlog Options
Option Name Description IntroducedDeprecated
-base64-output
Print binary log entries using base-64 encoding
-bind-address
Use specified network interface to connect to MySQL Server
-binlog-row-event-max-size
Binary log max event size
-character-sets-dir
Directory where character sets are installed
-connection-server-id
Used for testing and debugging. See text for applicable default values and other particulars
-database
List entries for just this database
-debug
Write debugging log
-debug-check
Print debugging information when program exits
-debug-info
Print debugging information, memory, and CPU statistics when program exits
-default-auth
Authentication plugin to use
-defaults-extra-file
Read named option file in addition to usual option files
-defaults-file
Read only named option file
-defaults-group-suffix
Option group suffix value
-disable-log-bin
Disable binary logging
-exclude-gtids
Do not show any of the groups in the GTID set provided
-force-if-open
Read binary log files even if open or not closed properly
-force-read
If mysqlbinlog reads a binary log event that it does not recognize, it prints a warning
-get-server-public-key
Request RSA 5.7.23 public key from
server
-help
Display help message and exit
-hexdump
Display a hex dump of the log in comments
-host
Host on which MySQL server is located
-idempotent
Cause the server to use idempotent mode while processing binary log updates from this session only
-include-gtids
Show only the groups in the GTID set provided
-local-load
Prepare local temporary files for LOAD DATA in the specified directory
-login-path
Read login path options from .mylogin.cnf
-no-defaults
Read no option files
-offset
Skip the first N entries in the log
-open-files-limit
Specify the number of open file descriptors to reserve
-password
Password to use when connecting to server
-plugin-dir
Directory where plugins are installed
-port
TCP/IP port number for connection
-print-defaults
Print default options
-protocol
Transport protocol to use
-raw
Write events in raw (binary) format to output files
-read-from-remote-master
Read the binary log from a MySQL replication source server rather than reading a local log file
-read-from-remote-server
Read binary log from MySQL server rather than local log file
-result-file
Direct output to named file
-rewrite-db
Create rewrite rules for databases when playing back from logs written in row-based format. Can be used multiple times
-secure-auth
Do not send Yes passwords to
server in old (pre-4.1) format
-server-id
Extract only those events created by the server having the given server ID
-server-id-bits
Tell mysqlbinlog how to interpret server IDs in binary log when log was written by a mysqld having its server-id-bits set to less than the maximum; supported only by MySQL Cluster version of mysqlbinlog
-server-public-key-path
Path name to file 5.7.23 containing RSA
public key
-set-charset
Add a SET NAMES charset_name statement to the output
-shared-memory-base-name
Shared-memory name for shared-memory connections (Windows only)
-short-form
Display only the statements contained in the log
-skip-gtids
Do not include the GTIDs from the binary log files in the output dump file
-socket
Unix socket file or Windows named pipe to use
-ssl
Enable connection encryption
-ssl-ca
File that contains list of trusted SSL Certificate Authorities
-ssl-capath
Directory that contains trusted SSL Certificate Authority certificate files
-ssl-cert
File that contains X.509 certificate
-ssl-cipher
Permissible ciphers for connection encryption
-ssl-crl
File that contains certificate revocation lists
-ssl-crlpath
Directory that contains certificate revocation-list files
-ssl-key
File that contains X.509 key
-ssl-mode
Desired security 5.7.11 state of
connection to server
-ssl-verify-server-cert
Verify host name against server certificate Common Name identity
-start-datetime
Read binary log from first event with timestamp equal to or later than datetime argument
-start-position
Decode binary log from first event with position equal to or greater than argument
-stop-datetime
Stop reading binary log at first event with timestamp equal to or greater than datetime argument
-stop-never
Stay connected to server after reading last binary log file
-stop-never-slave-server-id
Slave server ID to report when connecting to server
-stop-position
Stop decoding binary log at first event with position equal to or greater than argument
-tls-version
Permissible TLS 5.7.10 protocols for
encrypted connections
-to-last-log
Do not stop at the end of requested binary log from a MySQL server, but rather continue printing to end of last binary log
-user
MySQL user name to use when connecting to server
-verbose
Reconstruct row events as SQL statements
-verify-binlog-checksum
Verify checksums in binary log
-version
Display version information and exit
'--help', '-?'
Command-Line Format
'--help'
Display a help message and exit.
'--base64-output=VALUE'
Command-Line Format
'--base64-output=value'
Type
String
Default Value
'AUTO'
Valid Values
'AUTO' 'NEVER' 'DECODE-ROWS'
This option determines when events should be displayed encoded as base-64 strings using *note 'BINLOG': binlog. statements. The option has these permissible values (not case-sensitive):
* 'AUTO' ("automatic") or 'UNSPEC' ("unspecified") displays
*note 'BINLOG': binlog. statements automatically when
necessary (that is, for format description events and row
events). If no '--base64-output' option is given, the effect
is the same as '--base64-output=AUTO'.
*Note*:
Automatic *note 'BINLOG': binlog. display is the only safe
behavior if you intend to use the output of *note
'mysqlbinlog': mysqlbinlog. 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.
* 'NEVER' causes *note 'BINLOG': binlog. statements not to be
displayed. *note 'mysqlbinlog': mysqlbinlog. exits with an
error if a row event is found that must be displayed using
*note 'BINLOG': binlog.
* 'DECODE-ROWS' specifies to *note 'mysqlbinlog': mysqlbinlog.
that you intend for row events to be decoded and displayed as
commented SQL statements by also specifying the '--verbose'
option. Like 'NEVER', 'DECODE-ROWS' suppresses display of
*note 'BINLOG': binlog. statements, but unlike 'NEVER', it
does not exit with an error if a row event is found.
For examples that show the effect of '--base64-output' and '--verbose' on row event output, see *note mysqlbinlog-row-events::.
'--bind-address=IP_ADDRESS'
Command-Line Format
'--bind-address=ip_address'
On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server.
'--binlog-row-event-max-size=N'
Command-Line Format
'--binlog-row-event-max-size=#'
Type
Numeric
Default Value
'4294967040'
Minimum Value
'256'
Maximum Value
'18446744073709547520'
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.
'--character-sets-dir=DIR_NAME'
Command-Line Format
'--character-sets-dir=dir_name'
Type
Directory name
The directory where character sets are installed. See *note charset-configuration::.
'--connection-server-id=SERVER_ID'
Command-Line Format
'--connection-server-id=#]'
Type
Integer
Default Value
'0 (1)'
Minimum Value
'0 (1)'
Maximum Value
'4294967295'
This option is used to test a MySQL server for support of the 'BINLOG_DUMP_NON_BLOCK' connection flag. It is not required for normal operations.
The effective default and minimum values for this option depend on whether note 'mysqlbinlog': mysqlbinlog. is run in blocking mode or non-blocking mode. When note 'mysqlbinlog': mysqlbinlog. is run in blocking mode, the default (and minimum) value is 1; when run in non-blocking mode, the default (and minimum) value is 0.
'--database=DB_NAME', '-d DB_NAME'
Command-Line Format
'--database=db_name'
Type
String
This option causes note 'mysqlbinlog': mysqlbinlog. to output entries from the binary log (local log only) that occur while DB_NAME is been selected as the default database by note 'USE': use.
The '--database' option for note 'mysqlbinlog': mysqlbinlog. is similar to the '--binlog-do-db' option for note 'mysqld': mysqld, but can be used to specify only one database. If '--database' 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 '--binlog-do-db' depend on whether statement-based or row-based logging is in use.
Statement-based logging
The '--database' option works as follows:
* While DB_NAME is the default database, statements are output
whether they modify tables in DB_NAME or a different database.
* Unless DB_NAME is selected as the default database, statements
are not output, even if they modify tables in DB_NAME.
* There is an exception for *note 'CREATE DATABASE':
create-database, *note 'ALTER DATABASE': alter-database, and
*note 'DROP DATABASE': drop-database. 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:
INSERT INTO test.t1 (i) VALUES(100);
INSERT INTO db2.t2 (j) VALUES(200);
USE test;
INSERT INTO test.t1 (i) VALUES(101);
INSERT INTO t1 (i) VALUES(102);
INSERT INTO db2.t2 (j) VALUES(201);
USE db2;
INSERT INTO test.t1 (i) VALUES(103);
INSERT INTO db2.t2 (j) VALUES(202);
INSERT INTO t2 (j) VALUES(203);
note 'mysqlbinlog --database=test': mysqlbinlog. does not output the first two note 'INSERT': insert. statements because there is no default database. It outputs the three note 'INSERT': insert. statements following note 'USE test': use, but not the three note 'INSERT': insert. statements following note 'USE db2': use.
note 'mysqlbinlog --database=db2': mysqlbinlog. does not output the first two note 'INSERT': insert. statements because there is no default database. It does not output the three note 'INSERT': insert. statements following note 'USE test': use, but does output the three note 'INSERT': insert. statements following note 'USE db2': use.
Row-based logging
note 'mysqlbinlog': mysqlbinlog. outputs only entries that change tables belonging to DB_NAME. 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. note 'mysqlbinlog --database=test': mysqlbinlog. outputs only those entries that modify 't1' in the test database, regardless of whether *note 'USE': use. was issued or what the default database is.
If a server is running with 'binlog_format' set to 'MIXED' and you want it to be possible to use note 'mysqlbinlog': mysqlbinlog. with the '--database' option, you must ensure that tables that are modified are in the database selected by note 'USE': use. (In particular, no cross-database updates should be used.)
When used together with the '--rewrite-db' option, the '--rewrite-db' option is applied first; then the '--database' option is applied, using the rewritten database name. The order in which the options are provided makes no difference in this regard.
'--debug[=DEBUG_OPTIONS]', '-# [DEBUG_OPTIONS]'
Command-Line Format
'--debug[=debug_options]'
Type
String
Default Value
'd:t:o,/tmp/mysqlbinlog.trace'
Write a debugging log. A typical DEBUG_OPTIONS string is 'd:t:o,FILE_NAME'. The default is 'd:t:o,/tmp/mysqlbinlog.trace'.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--debug-check'
Command-Line Format
'--debug-check'
Type
Boolean
Default Value
'FALSE'
Print some debugging information when the program exits.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--debug-info'
Command-Line Format
'--debug-info'
Type
Boolean
Default Value
'FALSE'
Print debugging information and memory and CPU usage statistics when the program exits.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'--default-auth=PLUGIN'
Command-Line Format
'--default-auth=plugin'
Type
String
A hint about which client-side authentication plugin to use. See *note pluggable-authentication::.
'--defaults-extra-file=FILE_NAME'
Command-Line Format
'--defaults-extra-file=file_name'
Type
File name
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, an error occurs. If FILE_NAME is not an absolute path name, it is interpreted relative to the current directory.
For additional information about this and other option-file options, see *note option-file-options::.
'--defaults-file=FILE_NAME'
Command-Line Format
'--defaults-file=file_name'
Type
File name
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. If FILE_NAME is not an absolute path name, it is interpreted relative to the current directory.
Exception: Even with '--defaults-file', client programs read '.mylogin.cnf'.
For additional information about this and other option-file options, see *note option-file-options::.
'--defaults-group-suffix=STR'
Command-Line Format
'--defaults-group-suffix=str'
Type
String
Read not only the usual option groups, but also groups with the usual names and a suffix of STR. For example, *note 'mysqlbinlog': mysqlbinlog. normally reads the '[client]' and '[mysqlbinlog]' groups. If this option is given as '--defaults-group-suffix=_other', *note 'mysqlbinlog': mysqlbinlog. also reads the '[client_other]' and '[mysqlbinlog_other]' groups.
For additional information about this and other option-file options, see *note option-file-options::.
'--disable-log-bin', '-D'
Command-Line Format
'--disable-log-bin'
Disable binary logging. This is useful for avoiding an endless loop if you use the '--to-last-log' option and are sending the output to the same MySQL server. This option also is useful when restoring after an unexpected exit to avoid duplication of the statements you have logged.
This option causes note 'mysqlbinlog': mysqlbinlog. to include a note 'SET sql_log_bin = 0': set-sql-log-bin. statement in its output to disable binary logging of the remaining output. Manipulating the session value of the 'sql_log_bin' system variable is a restricted operation, so this option requires that you have privileges sufficient to set restricted session variables. See *note system-variable-privileges::.
'--exclude-gtids=GTID_SET'
Command-Line Format
'--exclude-gtids=gtid_set'
Type
String
Default Value
''
Do not display any of the groups listed in the GTID_SET.
'--force-if-open', '-F'
Command-Line Format
'--force-if-open'
Read binary log files even if they are open or were not closed properly.
'--force-read', '-f'
Command-Line Format
'--force-read'
With this option, if note 'mysqlbinlog': mysqlbinlog. reads a binary log event that it does not recognize, it prints a warning, ignores the event, and continues. Without this option, note 'mysqlbinlog': mysqlbinlog. stops if it reads such an event.
'--get-server-public-key'
Command-Line Format
'--get-server-public-key'
Introduced
5.7.23
Type
Boolean
Request from the server the public key required for RSA key pair-based password exchange. This option applies to clients that authenticate with the 'caching_sha2_password' authentication plugin. For that plugin, the server does not send the public key unless requested. This option is ignored for accounts that do not authenticate with that plugin. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.
If '--server-public-key-path=FILE_NAME' is given and specifies a valid public key file, it takes precedence over '--get-server-public-key'.
For information about the 'caching_sha2_password' plugin, see *note caching-sha2-pluggable-authentication::.
The '--get-server-public-key' option was added in MySQL 5.7.23.
'--hexdump', '-H'
Command-Line Format
'--hexdump'
Display a hex dump of the log in comments, as described in *note mysqlbinlog-hexdump::. The hex output can be helpful for replication debugging.
'--host=HOST_NAME', '-h HOST_NAME'
Command-Line Format
'--host=host_name'
Type
String
Default Value
'localhost'
Get the binary log from the MySQL server on the given host.
'--idempotent'
Command-Line Format
'--idempotent'
Type
Boolean
Default Value
'true'
Tell the MySQL Server to use idempotent mode while processing updates; this causes suppression of any duplicate-key or key-not-found errors that the server encounters in the current session while processing updates. This option may prove useful whenever it is desirable or necessary to replay one or more binary logs to a MySQL Server which may not contain all of the data to which the logs refer.
The scope of effect for this option includes the current *note 'mysqlbinlog': mysqlbinlog. client and session only.
'--include-gtids=GTID_SET'
Command-Line Format
'--include-gtids=gtid_set'
Type
String
Default Value
''
Display only the groups listed in the GTID_SET.
'--local-load=DIR_NAME', '-l DIR_NAME'
Command-Line Format
'--local-load=dir_name'
Type
Directory name
For data loading operations corresponding to note 'LOAD DATA': load-data. statements, note 'mysqlbinlog': mysqlbinlog. extracts the files from the binary log events, writes them as temporary files to the local file system, and writes note 'LOAD DATA LOCAL': load-data. statements to cause the files to be loaded. By default, note 'mysqlbinlog': mysqlbinlog. writes these temporary files to an operating system-specific directory. The '--local-load' option can be used to explicitly specify the directory where *note 'mysqlbinlog': mysqlbinlog. should prepare local temporary files.
Important:
These temporary files are not automatically removed by *note 'mysqlbinlog': mysqlbinlog. or any other MySQL program.
'--login-path=NAME'
Command-Line Format
'--login-path=name'
Type
String
Read options from the named login path in the '.mylogin.cnf' login path file. A 'login path' is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the note 'mysql_config_editor': mysql-config-editor. utility. See note mysql-config-editor::.
For additional information about this and other option-file options, see *note option-file-options::.
'--no-defaults'
Command-Line Format
'--no-defaults'
Do not read any option files. If program startup fails due to reading unknown options from an option file, '--no-defaults' can be used to prevent them from being read.
The exception is that the '.mylogin.cnf' file is read in all cases, if it exists. This permits passwords to be specified in a safer way than on the command line even when '--no-defaults' is used. To create '.mylogin.cnf', use the note 'mysql_config_editor': mysql-config-editor. utility. See note mysql-config-editor::.
For additional information about this and other option-file options, see *note option-file-options::.
'--offset=N', '-o N'
Command-Line Format
'--offset=#'
Type
Numeric
Skip the first N entries in the log.
'--open-files-limit=N'
Command-Line Format
'--open-files-limit=#'
Type
Numeric
Default Value
'8'
Minimum Value
'1'
Maximum Value
'[platform dependent]'
Specify the number of open file descriptors to reserve.
'--password[=PASSWORD]', '-p[PASSWORD]'
Command-Line Format
'--password[=password]'
Type
String
The password of the MySQL account used for connecting to the server. The password value is optional. If not given, *note 'mysqlbinlog': mysqlbinlog. prompts for one. If given, there must be no space between '--password=' or '-p' and the password following it. If no password option is specified, the default is to send no password.
Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See *note password-security-user::.
To explicitly specify that there is no password and that *note 'mysqlbinlog': mysqlbinlog. should not prompt for one, use the '--skip-password' option.
'--plugin-dir=DIR_NAME'
Command-Line Format
'--plugin-dir=dir_name'
Type
Directory name
The directory in which to look for plugins. Specify this option if the '--default-auth' option is used to specify an authentication plugin but note 'mysqlbinlog': mysqlbinlog. does not find it. See note pluggable-authentication::.
'--port=PORT_NUM', '-P PORT_NUM'
Command-Line Format
'--port=port_num'
Type
Numeric
Default Value
'3306'
The TCP/IP port number to use for connecting to a remote server.
'--print-defaults'
Command-Line Format
'--print-defaults'
Print the program name and all options that it gets from option files.
For additional information about this and other option-file options, see *note option-file-options::.
'--protocol={TCP|SOCKET|PIPE|MEMORY}'
Command-Line Format
'--protocol=type'
Type
String
Default Value
'[see text]'
Valid Values
'TCP' 'SOCKET' 'PIPE' 'MEMORY'
The transport protocol to use for connecting to the server. It is useful when the other connection parameters normally result in use of a protocol other than the one you want. For details on the permissible values, see *note transport-protocols::.
'--raw'
Command-Line Format
'--raw'
Type
Boolean
Default Value
'FALSE'
By default, note 'mysqlbinlog': mysqlbinlog. reads binary log files and writes events in text format. The '--raw' option tells note 'mysqlbinlog': mysqlbinlog. to write them in their original binary format. Its use requires that '--read-from-remote-server' also be used because the files are requested from a server. note 'mysqlbinlog': mysqlbinlog. writes one output file for each file read from the server. The '--raw' option can be used to make a backup of a server's binary log. With the '--stop-never' option, the backup is 'live' because note 'mysqlbinlog': mysqlbinlog. 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 '--result-file' option. For more information, see *note mysqlbinlog-backup::.
'--read-from-remote-master=TYPE'
Command-Line Format
'--read-from-remote-master=type'
Read binary logs from a MySQL server with the 'COM_BINLOG_DUMP' or 'COM_BINLOG_DUMP_GTID' commands by setting the option value to either 'BINLOG-DUMP-NON-GTIDS' or 'BINLOG-DUMP-GTIDS', respectively. If '--read-from-remote-master=BINLOG-DUMP-GTIDS' is combined with '--exclude-gtids', transactions can be filtered out on the source, avoiding unnecessary network traffic.
The connection parameter options are used with this option or the '--read-from-remote-server' option. These options are '--host', '--password', '--port', '--protocol', '--socket', and '--user'. If neither of the remote options is specified, the connection parameter options are ignored.
The 'REPLICATION SLAVE' privilege is required to use this option.
'--read-from-remote-server=FILE_NAME', '-R'
Command-Line Format
'--read-from-remote-server=file_name'
Read the binary log from a MySQL server rather than reading a local log file. This option requires that the remote server be running. It works only for binary log files on the remote server, not relay log files, and takes only the binary log file name (including the numeric suffix) as its argument, while ignoring any path.
The connection parameter options are used with this option or the '--read-from-remote-master' option. These options are '--host', '--password', '--port', '--protocol', '--socket', and '--user'. If neither of the remote options is specified, the connection parameter options are ignored.
The 'REPLICATION SLAVE' privilege is required to use this option.
This option is like '--read-from-remote-master=BINLOG-DUMP-NON-GTIDS'.
'--result-file=NAME', '-r NAME'
Command-Line Format
'--result-file=name'
Without the '--raw' option, this option indicates the file to which note 'mysqlbinlog': mysqlbinlog. writes text output. With '--raw', note 'mysqlbinlog': mysqlbinlog. 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 '--result-file' option value is treated as a prefix that modifies output file names.
'--rewrite-db='FROM_NAME->TO_NAME''
Command-Line Format
'--rewrite-db='oldname->newname''
Type
String
Default Value
'[none]'
When reading from a row-based or statement-based log, rewrite all occurrences of FROM_NAME to TO_NAME. Rewriting is done on the rows, for row-based logs, as well as on the *note 'USE': use. clauses, for statement-based logs. In MySQL versions prior to 5.7.8, this option was only for use when restoring tables logged using the row-based format.
Warning:
Statements in which table names are qualified with database names are not rewritten to use the new name when using this option.
The rewrite rule employed as a value for this option is a string having the form ''FROM_NAME->TO_NAME'', as shown previously, and for this reason must be enclosed by quotation marks.
To employ multiple rewrite rules, specify the option multiple times, as shown here:
mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
binlog.00001 > /tmp/statements.sql
When used together with the '--database' option, the '--rewrite-db' option is applied first; then '--database' option is applied, using the rewritten database name. The order in which the options are provided makes no difference in this regard.
This means that, for example, if note 'mysqlbinlog': mysqlbinlog. is started with '--rewrite-db='mydb->yourdb' --database=yourdb', then all updates to any tables in databases 'mydb' and 'yourdb' are included in the output. On the other hand, if it is started with '--rewrite-db='mydb->yourdb' --database=mydb', then note 'mysqlbinlog': mysqlbinlog. outputs no statements at all: since all updates to 'mydb' are first rewritten as updates to 'yourdb' before applying the '--database' option, there remain no updates that match '--database=mydb'.
'--secure-auth'
Command-Line Format
'--secure-auth'
Deprecated
Yes
Do not send passwords to the server in old (pre-4.1) format. This prevents connections except for servers that use the newer password format.
As of MySQL 5.7.5, this option is deprecated; expect it to be removed in a future MySQL release. It is always enabled and attempting to disable it ('--skip-secure-auth', '--secure-auth=0') produces an error. Before MySQL 5.7.5, this option is enabled by default but can be disabled.
Note:
Passwords that use the pre-4.1 hashing method are less secure than passwords that use the native password hashing method and should be avoided. Pre-4.1 passwords are deprecated and support for them was removed in MySQL 5.7.5. For account upgrade instructions, see *note account-upgrades::.
'--server-id=ID'
Command-Line Format
'--server-id=id'
Type
Numeric
Display only those events created by the server having the given server ID.
'--server-id-bits=N'
Command-Line Format
'--server-id-bits=#'
Type
Numeric
Default Value
'32'
Minimum Value
'7'
Maximum Value
'32'
Use only the first N bits of the 'server_id' to identify the server. If the binary log was written by a note 'mysqld': mysqld. with server-id-bits set to less than 32 and user data stored in the most significant bit, running note 'mysqlbinlog': mysqlbinlog. with '--server-id-bits' set to 32 enables this data to be seen.
This option is supported only by the version of *note 'mysqlbinlog': mysqlbinlog. supplied with the NDB Cluster distribution, or built with NDB Cluster support.
'--server-public-key-path=FILE_NAME'
Command-Line Format
'--server-public-key-path=file_name'
Introduced
5.7.23
Type
File name
The path name to a file in PEM format containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. This option applies to clients that authenticate with the 'sha256_password' or 'caching_sha2_password' authentication plugin. This option is ignored for accounts that do not authenticate with one of those plugins. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.
If '--server-public-key-path=FILE_NAME' is given and specifies a valid public key file, it takes precedence over '--get-server-public-key'.
For 'sha256_password', this option applies only if MySQL was built using OpenSSL.
For information about the 'sha256_password' and 'caching_sha2_password' plugins, see note sha256-pluggable-authentication::, and note caching-sha2-pluggable-authentication::.
The '--server-public-key-path' option was added in MySQL 5.7.23.
'--set-charset=CHARSET_NAME'
Command-Line Format
'--set-charset=charset_name'
Type
String
Add a *note 'SET NAMES CHARSET_NAME': set-names. statement to the output to specify the character set to be used for processing log files.
'--shared-memory-base-name=NAME'
Command-Line Format
'--shared-memory-base-name=name'
Platform Specific
Windows
On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value is 'MYSQL'. The shared-memory name is case-sensitive.
This option applies only if the server was started with the 'shared_memory' system variable enabled to support shared-memory connections.
'--short-form', '-s'
Command-Line Format
'--short-form'
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.
'--skip-gtids[=(true|false)]'
Command-Line Format
'--skip-gtids[=true|false]'
Type
Boolean
Default Value
'false'
Do not include the GTIDs from the binary log files in the output dump file. For example:
mysqlbinlog --skip-gtids binlog.000001 > /tmp/dump.sql
mysql -u root -p -e "source /tmp/dump.sql"
You should not normally use this option in production or in recovery, except in the specific, and rare, scenarios where the GTIDs are actively unwanted. For example, an administrator might want to duplicate selected transactions (such as table definitions) from a deployment to another, unrelated, deployment that will not replicate to or from the original. In that scenario, '--skip-gtids' can be used to enable the administrator to apply the transactions as if they were new, and ensure that the deployments remain unrelated. However, you should only use this option if the inclusion of the GTIDs causes a known issue for your use case.
'--socket=PATH', '-S PATH'
Command-Line Format
'--socket={file_name|pipe_name}'
Type
String
For connections to 'localhost', the Unix socket file to use, or, on Windows, the name of the named pipe to use.
On Windows, this option applies only if the server was started with the 'named_pipe' system variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by the 'named_pipe_full_access_group' system variable.
'--ssl*'
Options that begin with '--ssl' specify whether to connect to the server using encryption and indicate where to find SSL keys and certificates. See *note encrypted-connection-options::.
'--start-datetime=DATETIME'
Command-Line Format
'--start-datetime=datetime'
Type
Datetime
Start reading the binary log at the first event having a timestamp equal to or later than the DATETIME argument. The DATETIME value is relative to the local time zone on the machine where you run note 'mysqlbinlog': mysqlbinlog. The value should be in a format accepted for the note 'DATETIME': datetime. or *note 'TIMESTAMP': datetime. data types. For example:
mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
This option is useful for point-in-time recovery. See *note point-in-time-recovery::.
'--start-position=N', '-j N'
Command-Line Format
'--start-position=#'
Type
Numeric
Start reading the binary log at the first event having a position equal to or greater than N. This option applies to the first log file named on the command line.
This option is useful for point-in-time recovery. See *note point-in-time-recovery::.
'--stop-datetime=DATETIME'
Command-Line Format
'--stop-datetime=datetime'
Stop reading the binary log at the first event having a timestamp equal to or later than the DATETIME argument. See the description of the '--start-datetime' option for information about the DATETIME value.
This option is useful for point-in-time recovery. See *note point-in-time-recovery::.
'--stop-never'
Command-Line Format
'--stop-never'
Type
Boolean
Default Value
'FALSE'
This option is used with '--read-from-remote-server'. It tells note 'mysqlbinlog': mysqlbinlog. to remain connected to the server. Otherwise note 'mysqlbinlog': mysqlbinlog. exits when the last log file has been transferred from the server. '--stop-never' implies '--to-last-log', so only the first log file to transfer need be named on the command line.
'--stop-never' is commonly used with '--raw' to make a live binary log backup, but also can be used without '--raw' to maintain a continuous text display of log events as the server generates them.
'--stop-never-slave-server-id=ID'
Command-Line Format
'--stop-never-slave-server-id=#'
Type
Numeric
Default Value
'65535'
Minimum Value
'1'
With '--stop-never', note 'mysqlbinlog': mysqlbinlog. reports a server ID of 65535 when it connects to the server. '--stop-never-slave-server-id' explicitly specifies the server ID to report. It can be used to avoid a conflict with the ID of a replica server or another note 'mysqlbinlog': mysqlbinlog. process. See *note mysqlbinlog-server-id::.
'--stop-position=N'
Command-Line Format
'--stop-position=#'
Type
Numeric
Stop reading the binary log at the first event having a position equal to or greater than N. This option applies to the last log file named on the command line.
This option is useful for point-in-time recovery. See *note point-in-time-recovery::.
'--tls-version=PROTOCOL_LIST'
Command-Line Format
'--tls-version=protocol_list'
Introduced
5.7.10
Type
String
Default Value (≥ 5.7.28)
'TLSv1,TLSv1.1,TLSv1.2'
Default Value (<= 5.7.27)
'TLSv1,TLSv1.1,TLSv1.2' (OpenSSL) 'TLSv1,TLSv1.1' (yaSSL)
The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see *note encrypted-connection-protocols-ciphers::.
This option was added in MySQL 5.7.10.
'--to-last-log', '-t'
Command-Line Format
'--to-last-log'
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 '--read-from-remote-server'.
'--user=USER_NAME', '-u USER_NAME'
Command-Line Format
'--user=user_name,'
Type
String
The user name of the MySQL account to use when connecting to a remote server.
'--verbose', '-v'
Command-Line Format
'--verbose'
Reconstruct row events and display them as commented SQL statements. If this option is given twice (by passing in either "-vv" or "-verbose -verbose"), the output includes comments to indicate column data types and some metadata, and row query log events if so configured.
For examples that show the effect of '--base64-output' and '--verbose' on row event output, see *note mysqlbinlog-row-events::.
'--verify-binlog-checksum', '-c'
Command-Line Format
'--verify-binlog-checksum'
Verify checksums in binary log files.
'--version', '-V'
Command-Line Format
'--version'
Display version information and exit.
In MySQL 5.7, the version number shown by *note 'mysqlbinlog': mysqlbinlog. when using this option is 3.4.
You can pipe the output of note 'mysqlbinlog': mysqlbinlog. into the note 'mysql': mysql. client to execute the events contained in the binary log. This technique is used to recover from an unexpected exit when you have an old backup (see *note point-in-time-recovery::). For example:
mysqlbinlog binlog.000001 | mysql -u root -p
Or:
mysqlbinlog binlog.[0-9]* | mysql -u root -p
If the statements produced by note 'mysqlbinlog': mysqlbinlog. may contain note 'BLOB': blob. values, these may cause problems when note 'mysql': mysql. processes them. In this case, invoke note 'mysql': mysql. with the '--binary-mode' option.
You can also redirect the output of note 'mysqlbinlog': mysqlbinlog. 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 note 'mysql': mysql. program:
mysqlbinlog binlog.000001 > tmpfile
... EDIT TMPFILE ...
mysql -u root -p < tmpfile
When *note 'mysqlbinlog': mysqlbinlog. is invoked with the '--start-position' 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 '--stop-datetime' option (to be able to say, for example, 'roll forward my databases to how they were today at 10:30 a.m.').
Processing multiple files
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:
mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!
Processing binary logs this way using multiple connections to the server causes problems if the first log file contains a note 'CREATE TEMPORARY TABLE': create-table. statement and the second log contains a statement that uses the temporary table. When the first note 'mysql': mysql. process terminates, the server drops the temporary table. When the second *note 'mysql': mysql. process attempts to use the table, the server reports 'unknown table.'
To avoid problems like this, use a single *note 'mysql': mysql. process to execute the contents of all binary logs that you want to process. Here is one way to do so:
mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p
Another approach is to write all the logs to a single file and then process the file:
mysqlbinlog binlog.000001 > /tmp/statements.sql
mysqlbinlog binlog.000002 >> /tmp/statements.sql
mysql -u root -p -e "source /tmp/statements.sql"
note 'mysqlbinlog': mysqlbinlog. can produce output that reproduces a note 'LOAD DATA': load-data. operation without the original data file. note 'mysqlbinlog': mysqlbinlog. copies the data to a temporary file and writes a note 'LOAD DATA LOCAL': load-data. 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 '--local-load' option.
Because note 'mysqlbinlog': mysqlbinlog. converts note 'LOAD DATA': load-data. statements to note 'LOAD DATA LOCAL': load-data. statements (that is, it adds 'LOCAL'), both the client and the server that you use to process the statements must be configured with the 'LOCAL' capability enabled. See note load-data-local-security::.
Warning:
The temporary files created for *note 'LOAD DATA LOCAL': load-data. 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 ORIGINAL_FILE_NAME-#-#.
File: manual.info.tmp, Node: mysqlbinlog-hexdump, Next: mysqlbinlog-row-events, Prev: mysqlbinlog, Up: mysqlbinlog
4.6.7.1 mysqlbinlog Hex Dump Format ...................................
The '--hexdump' option causes *note 'mysqlbinlog': mysqlbinlog. to produce a hex dump of the binary log contents:
mysqlbinlog --hexdump master-bin.000001
The hex output consists of comment lines beginning with '#', so the output might look like this for the preceding command:
/*!40019 SET @@SESSION.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
# at 4
#051024 17:24:13 server id 1 end_log_pos 98
# Position Timestamp Type Master ID Size Master Pos Flags
# 00000004 9d fc 5c 43 0f 01 00 00 00 5e 00 00 00 62 00 00 00 00 00
# 00000017 04 00 35 2e 30 2e 31 35 2d 64 65 62 75 67 2d 6c |..5.0.15.debug.l|
# 00000027 6f 67 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |og..............|
# 00000037 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
# 00000047 00 00 00 00 9d fc 5c 43 13 38 0d 00 08 00 12 00 |.......C.8......|
# 00000057 04 04 04 04 12 00 00 4b 00 04 1a |.......K...|
# Start: binlog v 4, server v 5.0.15-debug-log created 051024 17:24:13
# at startup
ROLLBACK;
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 (https://dev.mysql.com/doc/internals/en/binary-log.html).
'Position': The byte position within the log file.
'Timestamp': The event timestamp. In the example shown, ''9d fc 5c 43'' is the representation of ''051024 17:24:13'' in hexadecimal.
'Type': The event type code.
'Master ID': The server ID of the replication source server that created the event.
'Size': The size in bytes of the event.
'Master Pos': The position of the next event in the original source log file.
'Flags': Event flag values.
File: manual.info.tmp, Node: mysqlbinlog-row-events, Next: mysqlbinlog-backup, Prev: mysqlbinlog-hexdump, Up: mysqlbinlog
4.6.7.2 mysqlbinlog Row Event Display .....................................
The following examples illustrate how *note 'mysqlbinlog': mysqlbinlog. displays row events that specify data modifications. These correspond to events with the 'WRITE_ROWS_EVENT', 'UPDATE_ROWS_EVENT', and 'DELETE_ROWS_EVENT' type codes. The '--base64-output=DECODE-ROWS' and '--verbose' 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:
CREATE TABLE t
(
id INT NOT NULL,
name VARCHAR(20) NOT NULL,
date DATE NULL
) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t VALUES(1, 'apple', NULL);
UPDATE t SET name = 'pear', date = '2009-01-01' WHERE id = 1;
DELETE FROM t WHERE id = 1;
COMMIT;
By default, note 'mysqlbinlog': mysqlbinlog. displays row events encoded as base-64 strings using note 'BINLOG': binlog. statements. Omitting extraneous lines, the output for the row events produced by the preceding statement sequence looks like this:
$> mysqlbinlog LOG_FILE
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
To see the row events as comments in the form of 'pseudo-SQL' statements, run *note 'mysqlbinlog': mysqlbinlog. with the '--verbose' or '-v' option. The output contains lines beginning with '###':
$> mysqlbinlog -v LOG_FILE
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
### INSERT INTO test.t
### SET
### @1=1
### @2='apple'
### @3=NULL
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
### UPDATE test.t
### WHERE
### @1=1
### @2='apple'
### @3=NULL
### SET
### @1=1
### @2='pear'
### @3='2009:01:01'
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
### DELETE FROM test.t
### WHERE
### @1=1
### @2='pear'
### @3='2009:01:01'
Specify '--verbose' or '-v' twice to also display data types and some metadata for each column. The output contains an additional comment following each column change:
$> mysqlbinlog -vv LOG_FILE
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
### INSERT INTO test.t
### SET
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
### UPDATE test.t
### WHERE
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
### SET
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
### DELETE FROM test.t
### WHERE
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
You can tell note 'mysqlbinlog': mysqlbinlog. to suppress the note 'BINLOG': binlog. statements for row events by using the '--base64-output=DECODE-ROWS' option. This is similar to '--base64-output=NEVER' but does not exit with an error if a row event is found. The combination of '--base64-output=DECODE-ROWS' and '--verbose' provides a convenient way to see row events only as SQL statements:
$> mysqlbinlog -v --base64-output=DECODE-ROWS LOG_FILE
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
### INSERT INTO test.t
### SET
### @1=1
### @2='apple'
### @3=NULL
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
### UPDATE test.t
### WHERE
### @1=1
### @2='apple'
### @3=NULL
### SET
### @1=1
### @2='pear'
### @3='2009:01:01'
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
### DELETE FROM test.t
### WHERE
### @1=1
### @2='pear'
### @3='2009:01:01'
Note:
You should not suppress note 'BINLOG': binlog. statements if you intend to re-execute note 'mysqlbinlog': mysqlbinlog. output.
The SQL statements produced by '--verbose' for row events are much more readable than the corresponding *note 'BINLOG': binlog. 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 '@N', where N 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 (*note 'BINARY': binary-varbinary. and
*note 'CHAR': char, *note 'VARBINARY': binary-varbinary. and
*note 'VARCHAR': char, *note 'BLOB': blob. and *note 'TEXT':
blob.). The output uses a data type of 'STRING' for
fixed-length strings and 'VARSTRING' for variable-length
strings.
* For multibyte 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, 'STRING(4)' is used as the data type for values
from either of these column types:
CHAR(4) CHARACTER SET latin1
CHAR(2) CHARACTER SET ucs2
* Due to the storage format for events of type
'UPDATE_ROWS_EVENT', *note 'UPDATE': update. statements are
displayed with the 'WHERE' clause preceding the 'SET' clause.
Proper interpretation of row events requires the information from the format description event at the beginning of the binary log. Because note 'mysqlbinlog': mysqlbinlog. does not know in advance whether the rest of the log contains row events, by default it displays the format description event using a note 'BINLOG': binlog. statement in the initial part of the output.
If the binary log is known not to contain any events requiring a *note 'BINLOG': binlog. statement (that is, no row events), the '--base64-output=NEVER' option can be used to prevent this header from being written.
File: manual.info.tmp, Node: mysqlbinlog-backup, Next: mysqlbinlog-server-id, Prev: mysqlbinlog-row-events, Up: mysqlbinlog
4.6.7.3 Using mysqlbinlog to Back Up Binary Log Files .....................................................
By default, note 'mysqlbinlog': mysqlbinlog. reads binary log files and displays their contents in text format. This enables you to examine events within the files more easily and to re-execute them (for example, by using the output as input to note 'mysql': mysql.). note 'mysqlbinlog': mysqlbinlog. can read log files directly from the local file system, or, with the '--read-from-remote-server' option, it can connect to a server and request binary log contents from that server. note 'mysqlbinlog': mysqlbinlog. writes text output to its standard output, or to the file named as the value of the '--result-file=FILE_NAME' option if that option is given.
*note mysqlbinlog-backup-capabilities::
*note mysqlbinlog-backup-options::
*note mysqlbinlog-backup-static-live::
*note mysqlbinlog-backup-output-file-naming::
*note mysqlbinlog-backup-example::
*note mysqlbinlog-backup-restrictions::
mysqlbinlog Backup Capabilities
note 'mysqlbinlog': mysqlbinlog. 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. note 'mysqlbinlog': mysqlbinlog. 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, note 'mysqlbinlog': mysqlbinlog. runs until the connection ends (for example, when the server exits) or note 'mysqlbinlog': mysqlbinlog. is forcibly terminated. When the connection ends, note 'mysqlbinlog': mysqlbinlog. does not wait and retry the connection, unlike a replica server. To continue a live backup after the server has been restarted, you must also restart note 'mysqlbinlog': mysqlbinlog.
mysqlbinlog Backup Options
Binary log backup requires that you invoke *note 'mysqlbinlog': mysqlbinlog. with two options at minimum:
The '--read-from-remote-server' (or '-R') option tells *note 'mysqlbinlog': mysqlbinlog. to connect to a server and request its binary log. (This is similar to a replica server connecting to its replication source server.)
The '--raw' option tells *note 'mysqlbinlog': mysqlbinlog. to write raw (binary) output, not text output.
Along with '--read-from-remote-server', it is common to specify other options: '--host' indicates where the server is running, and you may also need to specify connection options such as '--user' and '--password'.
Several other options are useful in conjunction with '--raw':
'--stop-never': Stay connected to the server after reaching the end of the last log file and continue to read new events.
'--stop-never-slave-server-id=ID': The server ID that note 'mysqlbinlog': mysqlbinlog. reports to the server when '--stop-never' is used. The default is 65535. This can be used to avoid a conflict with the ID of a replica server or another note 'mysqlbinlog': mysqlbinlog. process. See *note mysqlbinlog-server-id::.
'--result-file': A prefix for output file names, as described later.
Static and Live Backups
To back up a server's binary log files with note 'mysqlbinlog': mysqlbinlog, 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 note 'SHOW BINARY LOGS': show-binary-logs. statement to see the current names. Suppose that the statement produces this output:
mysql> SHOW BINARY LOGS;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000130 | 27459 |
| binlog.000131 | 13719 |
| binlog.000132 | 43268 |
+---------------+-----------+
With that information, you can use *note 'mysqlbinlog': mysqlbinlog. 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 'binlog.000130' through 'binlog.000132', use either of these commands:
mysqlbinlog --read-from-remote-server --host=HOST_NAME --raw
binlog.000130 binlog.000131 binlog.000132
mysqlbinlog --read-from-remote-server --host=HOST_NAME --raw
--to-last-log binlog.000130
The first command specifies every file name explicitly. The second names only the first file and uses '--to-last-log' to read through the last. A difference between these commands is that if the server happens to open 'binlog.000133' before *note 'mysqlbinlog': mysqlbinlog. reaches the end of 'binlog.000132', the first command does not read it, but the second command does.
To make a live backup in which *note 'mysqlbinlog': mysqlbinlog. starts with 'binlog.000130' to copy existing log files, then stays connected to copy new events as the server generates them:
mysqlbinlog --read-from-remote-server --host=HOST_NAME --raw
--stop-never binlog.000130
With '--stop-never', it is not necessary to specify '--to-last-log' to read to the last log file because that option is implied.
Output File Naming
Without '--raw', note 'mysqlbinlog': mysqlbinlog. produces text output and the '--result-file' option, if given, specifies the name of the single file to which all output is written. With '--raw', note 'mysqlbinlog': mysqlbinlog. writes one binary output file for each log file transferred from the server. By default, *note 'mysqlbinlog': mysqlbinlog. writes the files in the current directory with the same names as the original log files. To modify the output file names, use the '--result-file' option. In conjunction with '--raw', the '--result-file' option value is treated as a prefix that modifies the output file names.
Suppose that a server currently has binary log files named 'binlog.000999' and up. If you use *note 'mysqlbinlog --raw': mysqlbinlog. to back up the files, the '--result-file' option produces output file names as shown in the following table. You can write the files to a specific directory by beginning the '--result-file' value with the directory path. If the '--result-file' value consists only of a directory name, the value must end with the pathname separator character. Output files are overwritten if they exist.
'--result-file' Option Output File Names
'--result-file=x' 'xbinlog.000999' and up
'--result-file=/tmp/' '/tmp/binlog.000999' and up
'--result-file=/tmp/x' '/tmp/xbinlog.000999' and up
Example: mysqldump + mysqlbinlog for Backup and Restore
The following example describes a simple scenario that shows how to use note 'mysqldump': mysqldump. and note 'mysqlbinlog': mysqlbinlog. 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 HOST_NAME and its first binary log file is named 'binlog.000999'. Enter each command on a single line.
Use *note 'mysqlbinlog': mysqlbinlog. to make a continuous backup of the binary log:
mysqlbinlog --read-from-remote-server --host=HOST_NAME --raw
--stop-never binlog.000999
Use *note 'mysqldump': mysqldump. to create a dump file as a snapshot of the server's data. Use '--all-databases', '--events', and '--routines' to back up all data, and '--master-data=2' to include the current binary log coordinates in the dump file.
mysqldump --host=HOST_NAME --all-databases --events --routines --master-data=2> DUMP_FILE
Execute the *note 'mysqldump': mysqldump. command periodically to create newer snapshots as desired.
If data loss occurs (for example, if the server unexpectedly exits), use the most recent dump file to restore the data:
mysql --host=HOST_NAME -u root -p < DUMP_FILE
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:
-- CHANGE MASTER TO MASTER_LOG_FILE='binlog.001002', MASTER_LOG_POS=27284;
If the most recent backed-up log file is named 'binlog.001004', re-execute the log events like this:
mysqlbinlog --start-position=27284 binlog.001002 binlog.001003 binlog.001004
| mysql --host=HOST_NAME -u root -p
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 'root' access.
mysqlbinlog Backup Restrictions
Binary log backups with *note 'mysqlbinlog': mysqlbinlog. are subject to these restrictions:
*note 'mysqlbinlog': mysqlbinlog. does not automatically reconnect to the MySQL server if the connection is lost (for example, if a server restart occurs or there is a network outage).
Prior to MySQL 5.7.19, note 'mysqlbinlog': mysqlbinlog. does not get all events as they are committed, even if the server is configured with 'sync_binlog=1'. This means that some of the most recent events may be missing. To ensure that note 'mysqlbinlog': mysqlbinlog. sees the most recent events, flush the binary log on the server that you are backing up.
The delay for a backup is similar to the delay for a replica server.
File: manual.info.tmp, Node: mysqlbinlog-server-id, Prev: mysqlbinlog-backup, Up: mysqlbinlog
4.6.7.4 Specifying the mysqlbinlog Server ID ............................................
When invoked with the '--read-from-remote-server' option, note 'mysqlbinlog': mysqlbinlog. connects to a MySQL server, specifies a server ID to identify itself, and requests binary log files from the server. You can use note 'mysqlbinlog': mysqlbinlog. to request log files from a server in several ways:
Specify an explicitly named set of files: For each file, *note 'mysqlbinlog': mysqlbinlog. connects and issues a 'Binlog dump' command. The server sends the file and disconnects. There is one connection per file.
Specify the beginning file and '--to-last-log': *note 'mysqlbinlog': mysqlbinlog. connects and issues a 'Binlog dump' command for all files. The server sends all files and disconnects.
Specify the beginning file and '--stop-never' (which implies '--to-last-log'): *note 'mysqlbinlog': mysqlbinlog. connects and issues a 'Binlog dump' command for all files. The server sends all files, but does not disconnect after sending the last one.
With '--read-from-remote-server' only, *note 'mysqlbinlog': mysqlbinlog. connects using a server ID of 0, which tells the server to disconnect after sending the last requested log file.
With '--read-from-remote-server' and '--stop-never', *note 'mysqlbinlog': mysqlbinlog. 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 '--stop-never-slave-server-id'.
Thus, for the first two ways of requesting files, the server disconnects because note 'mysqlbinlog': mysqlbinlog. specifies a server ID of 0. It does not disconnect if '--stop-never' is given because note 'mysqlbinlog': mysqlbinlog. specifies a nonzero server ID.
File: manual.info.tmp, Node: mysqldumpslow, Prev: mysqlbinlog, Up: programs-admin-utils
The MySQL slow query log contains information about queries that take a long time to execute (see note slow-query-log::). note 'mysqldumpslow': mysqldumpslow. parses MySQL slow query log files and summarizes their contents.
Normally, *note 'mysqldumpslow': mysqldumpslow. groups queries that are similar except for the particular values of number and string data values. It 'abstracts' these values to 'N' and ''S'' when displaying summary output. To modify value abstracting behavior, use the '-a' and '-n' options.
Invoke *note 'mysqldumpslow': mysqldumpslow. like this:
mysqldumpslow [OPTIONS] [LOG_FILE ...]
Example output with no options given:
Reading mysql slow query log from /usr/local/mysql/data/mysqld57-slow.log
Count: 1 Time=4.32s (4s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
insert into t2 select * from t1
Count: 3 Time=2.53s (7s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
insert into t2 select * from t1 limit N
Count: 3 Time=2.13s (6s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
insert into t1 select * from t1
*note 'mysqldumpslow': mysqldumpslow. supports the following options.
mysqldumpslow Options
Option Name Description
-a Do not abstract all numbers to N and strings to 'S'
-n Abstract numbers with at least the specified digits
-debug Write debugging information
-g Only consider statements that match the pattern
-help Display help message and exit
-h Host name of the server in the log file name
-i Name of the server instance
-l Do not subtract lock time from total time
-r Reverse the sort order
-s How to sort output
-t Display only first num queries
-verbose Verbose mode
'--help'
Command-Line Format
'--help'
Display a help message and exit.
'-a'
Do not abstract all numbers to 'N' and strings to ''S''.
'--debug', '-d'
Command-Line Format
'--debug'
Run in debug mode.
This option is available only if MySQL was built using 'WITH_DEBUG'. MySQL release binaries provided by Oracle are not built using this option.
'-g PATTERN'
Type
String
Consider only queries that match the ('grep'-style) pattern.
'-h HOST_NAME'
Type
String
Default Value
'*'
Host name of MySQL server for '-slow.log' file name. The value can contain a wildcard. The default is '' (match all).
'-i NAME'
Type
String
Name of server instance (if using *note 'mysql.server': mysql-server. startup script).
'-l'
Do not subtract lock time from total time.
'-n N'
Type
Numeric
Abstract numbers with at least N digits within names.
'-r'
Reverse the sort order.
'-s SORT_TYPE'
Type
String
Default Value
'at'
How to sort the output. The value of SORT_TYPE should be chosen from the following list:
* 't', 'at': Sort by query time or average query time
* 'l', 'al': Sort by lock time or average lock time
* 'r', 'ar': Sort by rows sent or average rows sent
* 'c': Sort by count
By default, *note 'mysqldumpslow': mysqldumpslow. sorts by average query time (equivalent to '-s at').
'-t N'
Type
Numeric
Display only the first N queries in the output.
'--verbose', '-v'
Command-Line Format
'--verbose'
Verbose mode. Print more information about what the program does.
File: manual.info.tmp, Node: programs-development, Next: programs-miscellaneous, Prev: programs-admin-utils, Up: programs