Cari di MySQL 
    MySQL Manual
Daftar Isi
(Sebelumnya) 4.5. MySQL Client Programs5. MySQL Server Administration (Berikutnya)

4.6. MySQL Administrative and Utility Programs

This section describes administrative programs and programs that perform miscellaneous utility operations.

4.6.1. innochecksum - Offline InnoDB File Checksum Utility

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 will cause InnoDB to deliberately shut down a running server, it can be preferable to use this tool rather than waiting for a server in production usage to encounter the damaged pages.

innochecksum cannot be used on tablespace files that the server already has open. For such files, you should use CHECK TABLE to check tables within the tablespace.

If checksum mismatches are found, you would normally restore the tablespace from backup or start the server and attempt to use mysqldump to make a backup of the tables within the tablespace.

Invoke innochecksum like this:

shell> innochecksum [options] file_name

innochecksum supports the following options. For options that refer to page numbers, the numbers are zero-based.

  • -c

    Print a count of the number of pages in the file.

  • -d

    Debug mode; prints checksums for each page.

  • -e num

    End at this page number.

  • -p num

    Check only this page number.

  • -s num

    Start at this page number.

  • -v

    Verbose mode; print a progress indicator every five seconds.

4.6.2. myisam_ftdump - Display Full-Text Index information

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 myisam_ftdump, be sure to issue a FLUSH TABLES statement first if the server is running.

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 myisam_ftdump like this:

shell> 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 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 mytexttablel 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 myisam_ftdump as follows:

shell> 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 myisam_ftdump in the database directory:

shell> myisam_ftdump /usr/local/mysql/data/test/mytexttable 1

You can use myisam_ftdump to generate a list of index entries in order of frequency of occurrence like this:

shell> myisam_ftdump -c mytexttable 1 | sort -r

myisam_ftdump supports the following options:

  • --help, -h -?

    Display a help message and exit.

  • --count, -c

    Calculate per-word statistics (counts and global weights).

  • --dump, -d

    Dump the index, including data offsets and word weights.

  • --length, -l

    Report the length distribution.

  • --stats, -s

    Report global index statistics. This is the default operation if no other operation is specified.

  • --verbose, -v

    Verbose mode. Print more output about what the program does.

4.6.3. myisamchk - MyISAM Table-Maintenance Utility

The myisamchk utility gets information about your database tables or checks, repairs, or optimizes them. myisamchk works with MyISAM tables (tables that have .MYD and .MYI files for storing data and indexes).

You can also use the CHECK TABLE and REPAIR TABLE statements to check and repair MyISAM tables. See Section 13.7.2.2, "CHECK TABLE Syntax", and Section 13.7.2.5, "REPAIR TABLE Syntax".

The use of 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 myisamchk like this:

shell> myisamchk [options] tbl_name ...

The options specify what you want myisamchk to do. They are described in the following sections. You can also get a list of options by invoking myisamchk --help.

With no options, myisamchk simply checks your table as the default operation. To get more information or to tell 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 myisamchk somewhere other than in the database directory, you must specify the path to the database directory, because myisamchk has no idea where the database is located. In fact, 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 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:

shell> myisamchk *.MYI

If you are not in the database directory, you can check all the tables there by specifying the path to the directory:

shell> 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:

shell> myisamchk /path/to/datadir/*/*.MYI

The recommended way to quickly check all MyISAM tables is:

shell> 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:

shell> 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 myisamchk, see Section 4.6.3.6, "myisamchk Memory Usage".

For additional information about using myisamchk, see Section 7.6, "MyISAM Table Maintenance and Crash Recovery".

Important

You must ensure that no other program is using the tables while you are running myisamchk. The most effective means of doing so is to shut down the MySQL server while running myisamchk, or to lock all tables that myisamchk is being used on.

Otherwise, when you run 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 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 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 myisamchk

However, the easiest way to avoid this problem is to use CHECK TABLE instead of myisamchk to check tables. See Section 13.7.2.2, "CHECK TABLE Syntax".

myisamchk supports the following options, which can be specified on the command line or in the [myisamchk] group of an option file. myisamchk also supports the options for processing option files described at Section 4.2.3.4, "Command-Line Options that Affect Option-File Handling".

Table 4.9. myisamchk Options

FormatOption FileDescriptionIntroduced
--analyzeanalyzeAnalyze the distribution of key values 
--backupbackupMake a backup of the .MYD file as file_name-time.BAK 
--block-search=offsetblock-searchFind the record that a block at the given offset belongs to 
--checkcheckCheck the table for errors 
--check-only-changedcheck-only-changedCheck only tables that have changed since the last check 
--correct-checksumcorrect-checksumCorrect the checksum information for the table 
--data-file-length=lendata-file-lengthMaximum length of the data file (when re-creating data file when it is full) 
--debug[=debug_options]debugWrite a debugging log 
decode_bits=#decode_bitsDecode_bits 
--descriptiondescriptionPrint some descriptive information about the table 
--extend-checkextend-checkDo very thorough table check or repair that tries to recover every possible row from the data file 
--fastfastCheck only tables that haven't been closed properly 
--forceforceDo a repair operation automatically if myisamchk finds any errors in the table 
--forceforce-recoverOverwrite old temporary files. For use with the -r or -o option 
ft_max_word_len=#ft_max_word_lenMaximum word length for FULLTEXT indexes 
ft_min_word_len=#ft_min_word_lenMinimum word length for FULLTEXT indexes 
ft_stopword_file=valueft_stopword_fileUse stopwords from this file instead of built-in list 
--HELP Display help message and exit 
--help Display help message and exit 
--informationinformationPrint informational statistics about the table that is checked 
key_buffer_size=#key_buffer_sizeThe size of the buffer used for index blocks for MyISAM tables 
--keys-used=valkeys-usedA bit-value that indicates which indexes to update 
--max-record-length=lenmax-record-lengthSkip rows larger than the given length if myisamchk cannot allocate memory to hold them 
--medium-checkmedium-checkDo a check that is faster than an --extend-check operation 
myisam_block_size=#myisam_block_sizeBlock size to be used for MyISAM index pages 
myisam_sort_buffer_size=#myisam_sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE5.5.29
--parallel-recoverparallel-recoverUses the same technique as -r and -n, but creates all the keys in parallel, using different threads (beta) 
--quickquickAchieve a faster repair by not modifying the data file. 
read_buffer_size=#read_buffer_sizeEach thread that does a sequential scan allocates a buffer of this size for each table it scans 
--read-onlyread-onlyDon't mark the table as checked 
--recoverrecoverDo a repair that can fix almost any problem except unique keys that aren't unique 
--safe-recoversafe-recoverDo 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[=value]set-auto-incrementForce AUTO_INCREMENT numbering for new records to start at the given value 
--set-collation=nameset-collationSpecify the collation to use for sorting table indexes 
--silentsilentSilent mode 
sort_buffer_size=#sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE 
--sort-indexsort-indexSort the index tree blocks in high-low order 
sort_key_blocks=#sort_key_blockssort_key_blocks 
--sort-records=#sort-recordsSort records according to a particular index 
--sort-recoversort-recoverForce myisamchk to use sorting to resolve the keys even if the temporary files would be very large 
stats_method=valuestats_methodSpecifies how MyISAM index statistics collection code should treat NULLs 
--tmpdir=pathtmpdirPath of the directory to be used for storing temporary files 
--unpackunpackUnpack a table that was packed with myisampack 
--update-stateupdate-stateStore 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 
write_buffer_size=#write_buffer_sizeWrite buffer size 

4.6.3.1. myisamchk General Options

The options described in this section can be used for any type of table maintenance operation performed by myisamchk. The sections following this one describe options that pertain only to specific operations, such as table checking or repairing.

  • --help, -?

    Display a help message and exit. Options are grouped by type of operation.

  • --HELP, -H

    Display a help message and exit. Options are presented in a single list.

  • --debug=debug_options, -# debug_options

    Write a debugging log. A typical debug_options string is 'd:t:o,file_name'. The default is 'd:t:o,/tmp/myisamchk.trace'.

  • --silent, -s

    Silent mode. Write output only when errors occur. You can use -s twice (-ss) to make myisamchk very silent.

  • --verbose, -v

    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

    Display version information and exit.

  • --wait, -w

    Instead of terminating with an error if the table is locked, wait until the table is unlocked before continuing. If you are running mysqld with external locking disabled, the table can be locked only by another myisamchk command.

You can also set the following variables by using --var_name=value syntax:

VariableDefault Value
decode_bits9
ft_max_word_lenversion-dependent
ft_min_word_len4
ft_stopword_filebuilt-in list
key_buffer_size523264
myisam_block_size1024
myisam_sort_key_blocks16
read_buffer_size262136
sort_buffer_size2097144
sort_key_blocks16
stats_methodnulls_unequal
write_buffer_size262136

The possible myisamchk variables and their default values can be examined with myisamchk --help:

sort_buffer_size is used when the keys are repaired by sorting keys, which is the normal case when you use --recover. As of MySQL 5.5.29, myisam_sort_buffer_size is available as an alternative name to sort_buffer_size. myisam_sort_buffer_size is preferable to sort_buffer_size because its name corresponds to the myisam_sort_buffer_size server system variable that has a similar meaning. sort_buffer_size should be considered deprecated.

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 CHAR, VARCHAR, or TEXT 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 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 Section 5.1.4, "Server System Variables", and Section 8.3.7, "InnoDB and MyISAM Index Statistics Collection".

ft_min_word_len and ft_max_word_len indicate the minimum and maximum word length for FULLTEXT indexes. ft_stopword_file names the stopword file. These need to be set under the following circumstances.

If you use 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 myisamchk that you use for mysqld. For example, if you have set the minimum word length to 3, you can repair a table with myisamchk like this:

shell> myisamchk --recover --ft_min_word_len=3 tbl_name.MYI

To ensure that 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 myisamchk is to use the REPAIR TABLE, ANALYZE TABLE, OPTIMIZE TABLE, or ALTER TABLE. These statements are performed by the server, which knows the proper full-text parameter values to use.

4.6.3.2. myisamchk Check Options

myisamchk supports the following options for table checking operations:

  • --check, -c

    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

    Check only tables that have changed since the last check.

  • --extend-check, -e

    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, myisamchk or myisamchk --medium-check 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 Section 4.6.3.5, "Obtaining Table Information with myisamchk".

  • --fast, -F

    Check only tables that haven't been closed properly.

  • --force, -f

    Do a repair operation automatically if myisamchk finds any errors in the table. The repair type is the same as that specified with the --recover or -r option.

  • --information, -i

    Print informational statistics about the table that is checked.

  • --medium-check, -m

    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

    Do not mark the table as checked. This is useful if you use myisamchk to check a table that is in use by some other application that does not use locking, such as mysqld when run with external locking disabled.

  • --update-state, -U

    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 mysqld server is using the table and you are running it with external locking disabled.

4.6.3.3. myisamchk Repair Options

myisamchk supports the following options for table repair operations (operations performed when an option such as --recover or --safe-recover is given):

  • --backup, -B

    Make a backup of the .MYD file as file_name-time.BAK

  • --character-sets-dir=path

    The directory where character sets are installed. See Section 10.5, "Character Set Configuration".

  • --correct-checksum

    Correct the checksum information for the table.

  • --data-file-length=len, -D len

    The maximum length of the data file (when re-creating data file when it is "full").

  • --extend-check, -e

    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 Section 4.6.3.5, "Obtaining Table Information with myisamchk".

  • --force, -f

    Overwrite old intermediate files (files with names like tbl_name.TMD) instead of aborting.

  • --keys-used=val, -k val

    For 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 myisamchk -r.

  • --no-symlinks, -l

    Do not follow symbolic links. Normally myisamchk repairs the table that a symlink points to. This option does not exist as of MySQL 4.0 because versions from 4.0 on do not remove symlinks during repair operations.

  • --max-record-length=len

    Skip rows larger than the given length if myisamchk cannot allocate memory to hold them.

  • --parallel-recover, -p

    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

    Achieve a faster repair by modifying only the index file, not the data file. You can specify this option twice to force myisamchk to modify the original data file in case of duplicate keys.

  • --recover, -r

    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 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

    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-character-set=name

    Change the character set used by the table indexes. This option was replaced by --set-collation in MySQL 5.0.3.

  • --set-collation=name

    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

    Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large.

  • --tmpdir=path, -t path

    The path of the directory to be used for storing temporary files. If this is not set, 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

    Unpack a table that was packed with myisampack.

4.6.3.4. Other myisamchk Options

myisamchk supports the following options for actions other than table checks and repairs:

  • --analyze, -a

    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 myisamchk --description --verbose tbl_name command or the SHOW INDEX FROM tbl_name statement.

  • --block-search=offset, -b offset

    Find the record that a block at the given offset belongs to.

  • --description, -d

    Print some descriptive information about the table. Specifying the --verbose option once or twice produces additional information. See Section 4.6.3.5, "Obtaining Table Information with myisamchk".

  • --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

    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

    Sort records according to a particular index. This makes your data much more localized and may speed up range-based 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 SHOW INDEX, which displays a table's indexes in the same order that myisamchk sees them. Indexes are numbered beginning with 1.

    If keys are not packed (PACK_KEYS=0), they have the same length, so when myisamchk sorts and moves records, it just overwrites record offsets in the index. If keys are packed (PACK_KEYS=1), 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.)

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.

  • myisamchk -d tbl_name

    Runs myisamchk in "describe mode" to produce a description of your table. If you start the MySQL server with external locking disabled, myisamchk may report an error for a table that is updated while it runs. However, because myisamchk does not change the table in describe mode, there is no risk of destroying data.

  • myisamchk -dv tbl_name

    Adding -v runs myisamchk in verbose mode so that it produces more information about the table. Adding -v a second time produces even more information.

  • myisamchk -eis tbl_name

    Shows only the most important information from a table. This operation is slow because it must read the entire table.

  • myisamchk -eiv tbl_name

    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 Section 4.6.3, "myisamchk - MyISAM Table-Maintenance Utility". 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 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;

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 myisamchk -dvv output:

MyISAM file: personRecord format:   PackedCharacter set:   latin1_swedish_ci (8)File-version: 1Creation time:   2009-08-19 16:47:41Recover time: 2009-08-19 16:47:56Status:  checked,analyzed,optimized keysAuto increment key:  1  Last value: 306688Data records:   306688  Deleted blocks: 0Datafile parts: 306688  Deleted data:   0Datafile pointer (bytes): 4  Keyfile pointer (bytes): 3Datafile length:   9347072  Keyfile length:   6066176Max datafile length: 4294967294  Max keyfile length:   17179868159Recordlength:   54table description:Key Start Len Index   Type Rec/key Root  Blocksize1   2 4   unique  long   1 99328   10242   6 20  multip. varchar prefix   512  3563520   1024 27 20  varchar  5123   48 3   multip. uint24 NULL   306688  6065152   1024Field Start Length Nullpos Nullbit Type1 1 12 2 4  no zeros3 6 21 varchar4 27 21 varchar5 48 3  1   1   no zeros6 51 3  1   2   no zeros

Explanations for the types of information 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. Currently 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 Section 7.6.4, "MyISAM Table 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 Section 7.6.4, "MyISAM Table 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, 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 myisamchk -a. 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 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 myisampack. See Section 4.6.5, "myisampack - Generate Compressed, Read-Only MyISAM Tables", for an example of this information.

Example of myisamchk -eiv output:

Checking MyISAM file: personData records:  306688   Deleted blocks:   0- check file-size- check record delete-chainNo recordlinks- check key delete-chainblock_size 1024:- check index reference- check data record references index: 1Key:  1:  Keyblocks used:  98%  Packed: 0%  Max levels:  3- check data record references index: 2Key:  2:  Keyblocks used:  99%  Packed:   97%  Max levels:  3- check data record references index: 3Key:  3:  Keyblocks used:  98%  Packed:  -14%  Max levels:  3Total: 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.00Record blocks:  306688  Delete blocks: 0Record data:   7934464  Deleted data:  0Lost space: 256512  Linkdata: 1156096User time 43.08, System time 1.68Maximum resident set size 0, Integral resident set size 0Non-physical pagefaults 0, Physical pagefaults 0, Swaps 0Blocks in 0 out 7, Messages in 0 out 0, Signals 0Voluntary context switches 0, Involuntary context switches 0Maximum memory usage: 1046926 bytes (1023k)

myisamchk -eiv 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 Section 7.6.4, "MyISAM Table Optimization".

  • Key

    The key number.

  • Keyblocks used

    What percentage of the keyblocks are used. When a table has just been reorganized with 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 CHAR and VARCHAR 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 Section 7.6.4, "MyISAM Table 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.

4.6.3.6. myisamchk Memory Usage

Memory allocation is important when you run myisamchk. myisamchk uses no more memory than its memory-related variables are set to. If you are going to use 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 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):

shell> 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 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 myisamchk with the --tmpdir=path option to specify a directory located on a file system that has more space.

When performing repair operations, 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=path). 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 myisamchk -dv tbl_name (see Section 4.6.3.5, "Obtaining Table Information with myisamchk"). 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.

4.6.4. myisamlog - Display MyISAM Log File Contents

myisamlog processes the contents of a MyISAM log file.

Invoke myisamlog like this:

shell> myisamlog [options] [log_file [tbl_name] ...]shell> isamlog [options] [log_file [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 for myisamlog and isam.log for isamlog if no log_file argument is given. If tables are named on the command line, only those tables are updated.

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.

  • -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.

4.6.5. myisampack - Generate Compressed, Read-Only MyISAM Tables

The myisampack utility compresses MyISAM tables. myisampack works by compressing each column in the table separately. Usually, 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 mysqld server was invoked with external locking disabled, it is not a good idea to invoke 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).

Invoke myisampack like this:

shell> 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 myisampack, you should use myisamchk -rq to rebuild its indexes. Section 4.6.3, "myisamchk - MyISAM Table-Maintenance Utility".

myisampack supports the following options. It also reads option files and supports the options for processing them described at Section 4.2.3.4, "Command-Line Options that Affect Option-File Handling".

  • --help, -?

    Display a help message and exit.

  • --backup, -b

    Make a backup of each table's data file using the name tbl_name.OLD.

  • --character-sets-dir=path

    The directory where character sets are installed. See Section 10.5, "Character Set Configuration".

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

    Write a debugging log. A typical debug_options string is 'd:t:o,file_name'. The default is 'd:t:o'.

  • --force, -f

    Produce a packed table even if it becomes larger than the original or if the intermediate file from an earlier invocation of myisampack exists. (myisampack creates an intermediate file named tbl_name.TMD in the database directory while it compresses the table. If you kill myisampack, the .TMD file might not be deleted.) Normally, myisampack exits with an error if it finds that tbl_name.TMD exists. With --force, myisampack packs the table anyway.

  • --join=big_tbl_name, -j big_tbl_name

    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. The join operation does not create a .frm file for big_tbl_name, so after the join operation finishes, copy the .frm file from one of the source tables and name it big_tbl_name.frm.

  • --silent, -s

    Silent mode. Write output only when errors occur.

  • --test, -t

    Do not actually pack the table, just test packing it.

  • --tmpdir=path, -T path

    Use the named directory as the location where myisampack creates temporary files.

  • --verbose, -v

    Verbose mode. Write information about the progress of the packing operation and its result.

  • --version, -V

    Display version information and exit.

  • --wait, -w

    Wait and retry if the table is in use. If the mysqld server was invoked with external locking disabled, it is not a good idea to invoke 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:

shell> ls -l station.*-rw-rw-r--   1 monty my 994128 Apr 17 19:00 station.MYD-rw-rw-r--   1 monty my  53248 Apr 17 19:00 station.MYI-rw-rw-r--   1 monty my   5767 Apr 17 19:00 station.frmshell> myisamchk -dvv stationMyISAM file: stationIsam-version:  2Creation time: 1996-03-13 10:08:58Recover time:  1997-02-02  3:06:43Data records:  1192  Deleted blocks:  0Datafile parts: 1192  Deleted data: 0Datafile pointer (bytes): 2  Keyfile pointer (bytes): 2Max datafile length:   54657023  Max keyfile length:   33554431Recordlength:   834Record format: Fixed lengthtable description:Key Start Len Index   Type Root  Blocksize Rec/key1   2 4   unique  unsigned long 1024   1024  12   32 30  multip. text 10240   1024  1Field Start Length Type1 1 12 2 43 6 44 10 15 11 206 31 17 32 308 62 359 97 3510 132   3511 167   412 171   1613 187   3514 222   415 226   1616 242   2017 262   2018 282   2019 302   3020 332   421 336   422 340   123 341   824 349   825 357   826 365   227 367   228 369   429 373   430 377   131 378   232 380   833 388   434 392   435 396   436 400   437 404   138 405   439 409   440 413   441 417   442 421   443 425   444 429   2045 449   3046 479   147 480   148 481   7949 560   7950 639   7951 718   7952 797   853 805   154 806   155 807   2056 827   457 831   4shell> myisampack station.MYICompressing station.MYI: (1192 records)- Calculating statisticsnormal: 20  empty-space:   16  empty-zero: 12  empty-fill:  11pre-space:   0  end-space: 12  table-lookups:   5  zero: 7Original trees:  57  After join: 17- Compressing file87.14%Remember to run myisamchk -rq on compressed tablesshell> ls -l station.*-rw-rw-r--   1 monty my 127874 Apr 17 19:00 station.MYD-rw-rw-r--   1 monty my  55296 Apr 17 19:04 station.MYI-rw-rw-r--   1 monty my   5767 Apr 17 19:00 station.frmshell> myisamchk -dvv stationMyISAM file: stationIsam-version:  2Creation time: 1996-03-13 10:08:58Recover time:  1997-04-17 19:04:26Data records:   1192  Deleted blocks:  0Datafile parts: 1192  Deleted data: 0Datafile pointer (bytes):  3  Keyfile pointer (bytes): 1Max datafile length: 16777215  Max keyfile length: 131071Recordlength: 834Record format: Compressedtable description:Key Start Len Index   Type Root  Blocksize Rec/key1   2 4   unique  unsigned long   10240   1024  12   32 30  multip. text 54272   1024  1Field Start Length Type Huff tree  Bits1 1 1  constant 1 02 2 4  zerofill(1)  2 93 6 4  no zeros, zerofill(1) 2 94 10 1   3 95 11 20 table-lookup 4 06 31 1   3 97 32 30 no endspace, not_always  5 98 62 35 no endspace, not_always, no empty 6 99 97 35 no empty 7 910 132   35 no endspace, not_always, no empty 6 911 167   4  zerofill(1)  2 912 171   16 no endspace, not_always, no empty 5 913 187   35 no endspace, not_always, no empty 6 914 222   4  zerofill(1)  2 915 226   16 no endspace, not_always, no empty 5 916 242   20 no endspace, not_always  8 917 262   20 no endspace, no empty 8 918 282   20 no endspace, no empty 5 919 302   30 no endspace, no empty 6 920 332   4  always zero  2 921 336   4  always zero  2 922 340   1   3 923 341   8  table-lookup 9 024 349   8  table-lookup 10 025 357   8  always zero  2 926 365   2   2 927 367   2  no zeros, zerofill(1) 2 928 369   4  no zeros, zerofill(1) 2 929 373   4  table-lookup 11 030 377   1   3 931 378   2  no zeros, zerofill(1) 2 932 380   8  no zeros 2 933 388   4  always zero  2 934 392   4  table-lookup 12 035 396   4  no zeros, zerofill(1)   13 936 400   4  no zeros, zerofill(1) 2 937 404   1   2 938 405   4  no zeros 2 939 409   4  always zero  2 940 413   4  no zeros 2 941 417   4  always zero  2 942 421   4  no zeros 2 943 425   4  always zero  2 944 429   20 no empty 3 945 449   30 no empty 3 946 479   1  14 447 480   1  14 448 481   79 no endspace, no empty   15 949 560   79 no empty 2 950 639   79 no empty 2 951 718   79 no endspace 16 952 797   8  no empty 2 953 805   1  17 154 806   1   3 955 807   20 no empty 3 956 827   4  no zeros, zerofill(2) 2 957 831   4  no zeros, zerofill(1) 2 9

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 BIGINT column (eight bytes) can be stored as a TINYINT 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 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 myisamchk -dvv 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 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 myisampack, you must run 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:

shell> myisamchk -rq --sort-index --analyze tbl_name.MYI

After you have installed the packed table into the MySQL database directory, you should execute mysqladmin flush-tables to force mysqld to start using the new table.

To unpack a packed table, use the --unpack option to myisamchk.

4.6.6. mysqlaccess - Client for Checking Access Privileges

mysqlaccess is a diagnostic tool that Yves Carlier has provided for the MySQL distribution. It checks the access privileges for a host name, user name, and database combination. Note that mysqlaccess checks access using only the user, db, and host tables. It does not check table, column, or routine privileges specified in the tables_priv, columns_priv, or procs_priv tables.

Invoke mysqlaccess like this:

shell> mysqlaccess [host_name [user_name [db_name]]] [options]

mysqlaccess supports the following options.

Table 4.10. mysqlaccess Options

FormatOption FileDescription
--briefbriefGenerate reports in single-line tabular format
--commitcommitCopy the new access privileges from the temporary tables to the original grant tables
--copycopyReload the temporary grant tables from original ones
--db=db_namedbSpecify the database name
--debug=#debugSpecify the debug level
--help Display help message and exit
--host=host_namehostConnect to the MySQL server on the given host
--howtohowtoDisplay some examples that show how to use mysqlaccess
--old_serverold_serverAssume that the server is an old MySQL server (prior to MySQL 3.21)
--password[=password]passwordThe password to use when connecting to the server
--planplanDisplay suggestions and ideas for future releases
--previewpreviewShow the privilege differences after making changes to the temporary grant tables
--relnotesrelnotesDisplay the release notes
--rhost=host_namerhostConnect to the MySQL server on the given host
--rollbackrollbackUndo the most recent changes to the temporary grant tables.
--spassword[=password]spasswordThe password to use when connecting to the server as the superuser
--superuser=user_namesuperuserSpecify the user name for connecting as the superuser
--tabletableGenerate reports in table format
--user=user_name,userMySQL user name to use when connecting to server
--version Display version information and exit

If your MySQL distribution is installed in some nonstandard location, you must change the location where mysqlaccess expects to find the mysql client. Edit the mysqlaccess script at approximately line 18. Search for a line that looks like this:

$MYSQL = '/usr/local/bin/mysql'; # path to mysql executable

Change the path to reflect the location where mysql actually is stored on your system. If you do not do this, a Broken pipe error will occur when you run mysqlaccess.

4.6.7. mysqlbinlog - Utility for Processing Binary Log Files

The server's binary log consists of files containing "events" that describe modifications to database contents. The server writes these files in binary format. To display their contents in text format, use the mysqlbinlog utility. You can also use mysqlbinlog to display the contents of relay log files written by a slave server in a replication setup because relay logs have the same format as binary logs. The binary log and relay log are discussed further in Section 5.2.4, "The Binary Log", and Section 16.2.2, "Replication Relay and Status Logs".

Invoke mysqlbinlog like this:

shell> mysqlbinlog [options] log_file ...

For example, to display the contents of the binary log file named binlog.000003, use this command:

shell> mysqlbinlog binlog.0000003

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 Section 16.1.2, "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 starting position of the event in the binary log file.

The second line starts with a date and time indicating when the statement started on the server where the event originated. For replication, this timestamp is propagated to slave servers. 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 master server. On a slave, it is the difference of the end execution time on the slave minus the beginning execution time on the master. The difference serves as an indicator of how much replication lags behind the master. error_code indicates the result from executing the event. Zero means that no error occurred.

The output from mysqlbinlog can be re-executed (for example, by using it as input to mysql) to redo the statements in the log. This is useful for recovery operations after a server crash. For other usage examples, see the discussion later in this section and in Section 7.5, "Point-in-Time (Incremental) Recovery Using the Binary Log".

Normally, you use mysqlbinlog to read binary log files directly and apply them to the local MySQL server. It is also possible to read binary logs from a remote server by using the --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; they are ignored except when you also use the --read-from-remote-server option.

mysqlbinlog supports the following options, which can be specified on the command line or in the [mysqlbinlog] and [client] groups of an option file. mysqlbinlog also supports the options for processing option files described at Section 4.2.3.4, "Command-Line Options that Affect Option-File Handling".

Table 4.11. mysqlbinlog Options

FormatOption FileDescriptionIntroducedRemoved
--base64-output=valuebase64-outputPrint binary log entries using base-64 encoding  
--character-sets-dir=pathcharacter-sets-dirThe directory where character sets are installed  
--database=db_namedatabaseList entries for just this database  
--debug[=debug_options]debugWrite a debugging log  
--debug-checkdebug-checkPrint debugging information when the program exits  
--debug-infodebug-infoPrint debugging information, memory and CPU statistics when the program exits  
--default-auth=plugindefault-auth=pluginThe authentication plugin to use5.5.10 
--disable-log-bindisable-log-binDisable binary logging  
--force-if-openforce-if-openRead binary log files even if open or not closed properly  
--force-readforce-readIf mysqlbinlog reads a binary log event that it does not recognize, it prints a warning  
--help Display help message and exit  
--hexdumphexdumpDisplay a hex dump of the log in comments  
--host=host_namehostConnect to the MySQL server on the given host  
--local-load=pathlocal-loadPrepare local temporary files for LOAD DATA INFILE in the specified directory  
--offset=#offsetSkip the first N entries in the log  
--password[=password]passwordThe password to use when connecting to the server  
--plugin-dir=pathplugin-dir=pathThe directory where plugins are located5.5.10 
--port=port_numportThe TCP/IP port number to use for the connection  
--position=#positionDeprecated. Use --start-position 5.5.3
--protocol=typeprotocolThe connection protocol to use  
--read-from-remote-serverread-from-remote-serverRead binary log from MySQL server rather than local log file  
--result-file=nameresult-fileDirect output to the given file  
--server-id=idserver-idExtract only those events created by the server having the given server ID  
--set-charset=charset_nameset-charsetAdd a SET NAMES charset_name statement to the output  
--short-formshort-formDisplay only the statements contained in the log  
--socket=pathsocketFor connections to localhost  
--start-datetime=datetimestart-datetimeRead binary log from first event with timestamp equal to or later than datetime argument  
--start-position=#start-positionRead binary log from first event with position equal to or greater than argument  
--stop-datetime=datetimestop-datetimeStop reading binary log at first event with timestamp equal to or greater than datetime argument  
--stop-position=#stop-positionStop reading binary log at first event with position equal to or greater than argument  
--to-last-logto-last-logDo not stop at the end of requested binary log from a MySQL server, but rather continue printing to end of last binary log  
--user=user_name,userMySQL user name to use when connecting to server  
--verbose Reconstruct row events as SQL statements  
--version Display version information and exit  

  • --help, -?

    Display a help message and exit.

  • --base64-output[=value]

    This option determines when events should be displayed encoded as base-64 strings using BINLOG statements. The option has these permissible values (not case sensitive):

    • AUTO ("automatic") or UNSPEC ("unspecified") displays 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 BINLOG display is the only safe behavior if you intend to use the output of 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.

    • ALWAYS displays BINLOG statements whenever possible. If the --base64-output option is given without a value, the effect is the same as --base64-output=ALWAYS.

      Note

      Changes to replication in MySQL 5.6 make output generated by this option unusable, so ALWAYS is deprecated as of MySQL 5.5.8 and will be an invalid value in MySQL 5.6

    • NEVER causes BINLOG statements not to be displayed. mysqlbinlog exits with an error if a row event is found that must be displayed using BINLOG.

    • DECODE-ROWS specifies to 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 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 Section 4.6.7.2, "mysqlbinlog Row Event Display".

  • --bind-address=ip_address

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

    This option is supported beginning with MySQL 5.5.8.

  • --character-sets-dir=path

    The directory where character sets are installed. See Section 10.5, "Character Set Configuration".

  • --database=db_name, -d db_name

    This option causes mysqlbinlog to output entries from the binary log (local log only) that occur while db_name is been selected as the default database by USE.

    The --database option for mysqlbinlog is similar to the --binlog-do-db option for 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 CREATE DATABASE, ALTER DATABASE, and 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);

    mysqlbinlog --database=test does not output the first two INSERT statements because there is no default database. It outputs the three INSERT statements following USE test, but not the three INSERT statements following USE db2.

    mysqlbinlog --database=db2 does not output the first two INSERT statements because there is no default database. It does not output the three INSERT statements following USE test, but does output the three INSERT statements following USE db2.

    Row-based logging. 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. mysqlbinlog --database=test outputs only those entries that modify t1 in the test database, regardless of whether 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 mysqlbinlog with the --database option, you must ensure that tables that are modified are in the database selected by USE. (In particular, no cross-database updates should be used.)

    Note

    Prior to MySQL Cluster NDB 7.2.2, this option did not work correctly with MySQL Cluster tables unless, unless the binary log was generated using --log-bin-use-v1-row-events=0. (Bug #13067813)

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

    Write a debugging log. A typical debug_options string is 'd:t:o,file_name'. The default is 'd:t:o,/tmp/mysqlbinlog.trace'.

  • --debug-check

    Print some debugging information when the program exits.

  • --debug-info

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

  • --default-auth=plugin

    The client-side authentication plugin to use. See Section 6.3.6, "Pluggable Authentication".

    This option was added in MySQL 5.5.10.

  • --disable-log-bin, -D

    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 a crash to avoid duplication of the statements you have logged.

    This option requires that you have the SUPER privilege. It causes mysqlbinlog to include a SET sql_log_bin = 0 statement in its output to disable binary logging of the remaining output. The SET statement is ineffective unless you have the SUPER privilege.

  • --force-if-open, -F

    Read binary log files even if they are open or were not closed properly.

  • --force-read, -f

    With this option, if mysqlbinlog reads a binary log event that it does not recognize, it prints a warning, ignores the event, and continues. Without this option, mysqlbinlog stops if it reads such an event.

  • --hexdump, -H

    Display a hex dump of the log in comments, as described in Section 4.6.7.1, "mysqlbinlog Hex Dump Format". The hex output can be helpful for replication debugging.

  • --host=host_name, -h host_name

    Get the binary log from the MySQL server on the given host.

  • --local-load=path, -l path

    Prepare local temporary files for LOAD DATA INFILE in the specified directory.

    Important

    These temporary files are not automatically removed by mysqlbinlog or any other MySQL program.

  • --offset=N, -o N

    Skip the first N entries in the log.

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

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

    Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, "End-User Guidelines for Password Security". You can use an option file to avoid giving the password on the command line.

  • --plugin-dir=path

    The directory in which to look for plugins. It may be necessary to specify this option if the --default-auth option is used to specify an authentication plugin but mysqlbinlog does not find it. See Section 6.3.6, "Pluggable Authentication".

    This option was added in MySQL 5.5.10.

  • --port=port_num, -P port_num

    The TCP/IP port number to use for connecting to a remote server.

  • --position=N

    Deprecated. Use --start-position instead. --position was removed in MySQL 5.5.3.

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

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

  • --read-from-remote-server, -R

    Read the binary log from a MySQL server rather than reading a local log file. Any connection parameter options are ignored unless this option is given as well. These options are --host, --password, --port, --protocol, --socket, and --user.

    This option requires that the remote server be running. It works only for binary log files on the remote server, not relay log files.

  • --result-file=name, -r name

    Direct output to the given file.

  • --server-id=id

    Display only those events created by the server having the given server ID.

  • --server-id-bits=N

    Use only the first N bits of the server_id to identify the server. If the binary log was written by a mysqld with server-id-bits set to less than 32 and user data stored in the most significant bit, running mysqlbinlog with --server-id-bits set to 32 enables this data to be seen.

    This option is supported only by the versions of mysqlbinlog supplied with the MySQL Cluster distribution, or built from the MySQL Cluster sources.

  • --set-charset=charset_name

    Add a SET NAMES charset_name statement to the output to specify the character set to be used for processing log files.

  • --short-form, -s

    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.

  • --socket=path, -S path

    For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

  • --start-datetime=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 mysqlbinlog. The value should be in a format accepted for the DATETIME or TIMESTAMP data types. For example:

    shell> mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003

    This option is useful for point-in-time recovery. See Section 7.3, "Example Backup and Recovery Strategy".

  • --start-position=N, -j N

    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 Section 7.3, "Example Backup and Recovery Strategy".

  • --stop-datetime=datetime

    Stop reading the binary log at the first event having a timestamp equal to or later than the datetime argument. This option is useful for point-in-time recovery. See the description of the --start-datetime option for information about the datetime value.

    This option is useful for point-in-time recovery. See Section 7.3, "Example Backup and Recovery Strategy".

  • --stop-position=N

    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 Section 7.3, "Example Backup and Recovery Strategy".

  • --to-last-log, -t

    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

    The MySQL user name to use when connecting to a remote server.

  • --verbose, -v

    Reconstruct row events and display them as commented SQL statements. If this option is given twice, the output includes comments to indicate column data types and some metadata.

    For examples that show the effect of --base64-output and --verbose on row event output, see Section 4.6.7.2, "mysqlbinlog Row Event Display".

  • --version, -V

    Display version information and exit.

You can also set the following variable by using --var_name=value syntax:

  • open_files_limit

    Specify the number of open file descriptors to reserve.

You can pipe the output of mysqlbinlog into the mysql client to execute the events contained in the binary log. This technique is used to recover from a crash when you have an old backup (see Section 7.5, "Point-in-Time (Incremental) Recovery Using the Binary Log"). For example:

shell> mysqlbinlog binlog.000001 | mysql -u root -p

Or:

shell> mysqlbinlog binlog.[0-9]* | mysql -u root -p

You can also redirect the output of 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 mysql program:

shell> mysqlbinlog binlog.000001 > tmpfileshell> ... edit tmpfile ...shell> mysql -u root -p < tmpfile

When 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.").

If you have more than one binary log to execute on the MySQL server, the safe method is to process them all using a single connection to the server. Here is an example that demonstrates what may be unsafe:

shell> mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!shell> 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 CREATE TEMPORARY TABLE statement and the second log contains a statement that uses the temporary table. When the first mysql process terminates, the server drops the temporary table. When the second mysql process attempts to use the table, the server reports "unknown table."

To avoid problems like this, use a single mysql process to execute the contents of all binary logs that you want to process. Here is one way to do so:

shell> 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:

shell> mysqlbinlog binlog.000001 >  /tmp/statements.sqlshell> mysqlbinlog binlog.000002 >> /tmp/statements.sqlshell> mysql -u root -p -e "source /tmp/statements.sql"

mysqlbinlog can produce output that reproduces a LOAD DATA INFILE operation without the original data file. mysqlbinlog copies the data to a temporary file and writes a LOAD DATA LOCAL INFILE 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 mysqlbinlog converts LOAD DATA INFILE statements to LOAD DATA LOCAL INFILE 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 Section 6.1.6, "Security Issues with LOAD DATA LOCAL".

Warning

The temporary files created for LOAD DATA LOCAL 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-#-#.

4.6.7.1. mysqlbinlog Hex Dump Format

The --hexdump option causes mysqlbinlog to produce a hex dump of the binary log contents:

shell> 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 startupROLLBACK;

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.

  • 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. In the example shown, '0f' indicates a FORMAT_DESCRIPTION_EVENT. The following table lists the possible type codes.

    TypeNameMeaning
    00UNKNOWN_EVENTThis event should never be present in the log.
    01START_EVENT_V3This indicates the start of a log file written by MySQL 4 or earlier.
    02QUERY_EVENTThe most common type of events. These contain statements executed on the master.
    03STOP_EVENTIndicates that master has stopped.
    04ROTATE_EVENTWritten when the master switches to a new log file.
    05INTVAR_EVENTUsed for AUTO_INCREMENT values or when the LAST_INSERT_ID() function is used in the statement.
    06LOAD_EVENTUsed for LOAD DATA INFILE in MySQL 3.23.
    07SLAVE_EVENTReserved for future use.
    08CREATE_FILE_EVENTUsed for LOAD DATA INFILE statements. This indicates the start of execution of such a statement. A temporary file is created on the slave. Used in MySQL 4 only.
    09APPEND_BLOCK_EVENTContains data for use in a LOAD DATA INFILE statement. The data is stored in the temporary file on the slave.
    0aEXEC_LOAD_EVENTUsed for LOAD DATA INFILE statements. The contents of the temporary file is stored in the table on the slave. Used in MySQL 4 only.
    0bDELETE_FILE_EVENTRollback of a LOAD DATA INFILE statement. The temporary file should be deleted on the slave.
    0cNEW_LOAD_EVENTUsed for LOAD DATA INFILE in MySQL 4 and earlier.
    0dRAND_EVENTUsed to send information about random values if the RAND() function is used in the statement.
    0eUSER_VAR_EVENTUsed to replicate user variables.
    0fFORMAT_DESCRIPTION_EVENTThis indicates the start of a log file written by MySQL 5 or later.
    10XID_EVENTEvent indicating commit of an XA transaction.
    11BEGIN_LOAD_QUERY_EVENTUsed for LOAD DATA INFILE statements in MySQL 5 and later.
    12EXECUTE_LOAD_QUERY_EVENTUsed for LOAD DATA INFILE statements in MySQL 5 and later.
    13TABLE_MAP_EVENTInformation about a table definition. Used in MySQL 5.1.5 and later.
    14PRE_GA_WRITE_ROWS_EVENTRow data for a single table that should be created. Used in MySQL 5.1.5 to 5.1.17.
    15PRE_GA_UPDATE_ROWS_EVENTRow data for a single table that needs to be updated. Used in MySQL 5.1.5 to 5.1.17.
    16PRE_GA_DELETE_ROWS_EVENTRow data for a single table that should be deleted. Used in MySQL 5.1.5 to 5.1.17.
    17WRITE_ROWS_EVENTRow data for a single table that should be created. Used in MySQL 5.1.18 and later.
    18UPDATE_ROWS_EVENTRow data for a single table that needs to be updated. Used in MySQL 5.1.18 and later.
    19DELETE_ROWS_EVENTRow data for a single table that should be deleted. Used in MySQL 5.1.18and later.
    1aINCIDENT_EVENTSomething out of the ordinary happened. Added in MySQL 5.1.18.
  • Master ID: The server ID of the master that created the event.

  • Size: The size in bytes of the event.

  • Master Pos: The position of the next event in the original master log file.

  • Flags: 16 flags. Currently, the following flags are used. The others are reserved for future use.

    FlagNameMeaning
    01LOG_EVENT_BINLOG_IN_USE_FLog file correctly closed. (Used only in FORMAT_DESCRIPTION_EVENT.) If this flag is set (if the flags are, for example, '01 00') in a FORMAT_DESCRIPTION_EVENT, the log file has not been properly closed. Most probably this is because of a master crash (for example, due to power failure).
    02 Reserved for future use.
    04LOG_EVENT_THREAD_SPECIFIC_FSet if the event is dependent on the connection it was executed in (for example, '04 00'), for example, if the event uses temporary tables.
    08LOG_EVENT_SUPPRESS_USE_FSet in some circumstances when the event is not dependent on the defaultdatabase.

4.6.7.2. mysqlbinlog Row Event Display

The following examples illustrate how 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, mysqlbinlog displays row events encoded as base-64 strings using BINLOG statements. Omitting extraneous lines, the output for the row events produced by the preceding statement sequence looks like this:

shell> mysqlbinlog log_file...# at 218#080828 15:03:08 server id 1  end_log_pos 258 Write_rows: table id 17 flags: STMT_END_FBINLOG 'fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ=='/*!*/;...# at 302#080828 15:03:08 server id 1  end_log_pos 356 Update_rows: table id 17 flags: STMT_END_FBINLOG 'fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP'/*!*/;...# at 400#080828 15:03:08 server id 1  end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_FBINLOG 'fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP'/*!*/;

To see the row events as comments in the form of "pseudo-SQL" statements, run mysqlbinlog with the --verbose or -v option. The output will contain lines beginning with ###:

shell> 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_FBINLOG '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_FBINLOG '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_FBINLOG '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 will contain an additional comment following each column change:

shell> 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_FBINLOG '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_FBINLOG '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_FBINLOG '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 mysqlbinlog to suppress the 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:

shell> 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 BINLOG statements if you intend to re-execute mysqlbinlog output.

The SQL statements produced by --verbose for row events are much more readable than the corresponding 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 (BINARY and CHAR, VARBINARY and VARCHAR, BLOB and TEXT). The output uses a data type of STRING for fixed-length strings and VARSTRING for variable-length strings.

    • For multi-byte character sets, the maximum number of bytes per character is not present in the binary log, so the length for string types is displayed in bytes rather than in characters. For example, STRING(4) will be used as the data type for values from either of these column types:

      CHAR(4) CHARACTER SET latin1CHAR(2) CHARACTER SET ucs2
    • Due to the storage format for events of type UPDATE_ROWS_EVENT, 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 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 BINLOG statement in the initial part of the output.

If the binary log is known not to contain any events requiring a BINLOG statement (that is, no row events), the --base64-output=NEVER option can be used to prevent this header from being written.

4.6.8. mysqldumpslow - Summarize Slow Query Log Files

The MySQL slow query log contains information about queries that take a long time to execute (see Section 5.2.5, "The Slow Query Log"). mysqldumpslow parses MySQL slow query log files and prints a summary of their contents.

Normally, 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. The -a and -n options can be used to modify value abstracting behavior.

Invoke mysqldumpslow like this:

shell> mysqldumpslow [options] [log_file ...]

mysqldumpslow supports the following options.

Table 4.12. mysqldumpslow Options

FormatOption FileDescription
-a Do not abstract all numbers to N and strings to S
-n num Abstract numbers with at least the specified digits
--debugdebugWrite debugging information
-g pattern Only consider statements that match the pattern
--help Display help message and exit
-h name Host name of the server in the log file name
-i name Name of the server instance
-l Do not subtract lock time from total time
-r Reverse the sort order
-s value How to sort output
-t num Display only first num queries
--verboseverboseVerbose mode

  • --help

    Display a help message and exit.

  • -a

    Do not abstract all numbers to N and strings to 'S'.

  • --debug, -d

    Run in debug mode.

  • -g pattern

    Consider only queries that match the (grep-style) pattern.

  • -h host_name

    Host name of MySQL server for *-slow.log file name. The value can contain a wildcard. The default is * (match all).

  • -i name

    Name of server instance (if using mysql.server startup script).

  • -l

    Do not subtract lock time from total time.

  • -n N

    Abstract numbers with at least N digits within names.

  • -r

    Reverse the sort order.

  • -s sort_type

    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, mysqldumpslow sorts by average query time (equivalent to -s at).

  • -t N

    Display only the first N queries in the output.

  • --verbose, -v

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

Example of usage:

shell> mysqldumpslowReading mysql slow query log from /usr/local/mysql/data/mysqld51-apple-slow.logCount: 1  Time=4.32s (4s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost insert into t2 select * from t1Count: 3  Time=2.53s (7s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost insert into t2 select * from t1 limit NCount: 3  Time=2.13s (6s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost insert into t1 select * from t1

4.6.9. mysqlhotcopy - A Database Backup Program

mysqlhotcopy is a Perl script that was originally written and contributed by Tim Bunce. It uses FLUSH TABLES, LOCK TABLES, and cp or scp to make a database backup. It is a fast way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located. mysqlhotcopy works only for backing up MyISAM and ARCHIVE tables. It runs on Unix.

To use mysqlhotcopy, you must have read access to the files for the tables that you are backing up, the SELECT privilege for those tables, the RELOAD privilege (to be able to execute FLUSH TABLES), and the LOCK TABLES privilege (to be able to lock the tables).

shell> mysqlhotcopy db_name [/path/to/new_directory]
shell> mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory

Back up tables in the given database that match a regular expression:

shell> mysqlhotcopy db_name./regex/

The regular expression for the table name can be negated by prefixing it with a tilde ("~"):

shell> mysqlhotcopy db_name./~regex/

mysqlhotcopy supports the following options, which can be specified on the command line or in the [mysqlhotcopy] and [client] groups of an option file. For information about option files, see Section 4.2.3.3, "Using Option Files".

Table 4.13. mysqlhotcopy Options

FormatOption FileDescriptionIntroduced
--addtodestaddtodestDo not rename target directory (if it exists); merely add files to it 
--allowoldallowoldDo not abort if a target exists; rename it by adding an _old suffix 
--checkpoint=db_name.tbl_namecheckpointInsert checkpoint entries 
--chroot=pathchrootBase directory of the chroot jail in which mysqld operates 
--debugdebugWrite a debugging log 
--dryrundryrunReport actions without performing them 
--flushlogflushlogFlush logs after all tables are locked 
--help Display help message and exit 
--host=host_namehostConnect to the MySQL server on the given host 
--keepoldkeepoldDo not delete previous (renamed) target when done 
--methodmethodThe method for copying files 
--noindicesnoindicesDo not include full index files in the backup 
--old_serverold_serverConnect to server that does not support FLUSH TABLES tbl_list WITH READ LOCK5.5.3
--password[=password]passwordThe password to use when connecting to the server 
--port=port_numportThe TCP/IP port number to use for the connection 
--quietquietBe silent except for errors 
--regexpregexpCopy all databases with names that match the given regular expression 
--resetmasterresetmasterReset the binary log after locking all the tables 
--resetslaveresetslaveReset the master.info file after locking all the tables 
--socket=pathsocketFor connections to localhost 
--tmpdir=pathtmpdirThe temporary directory 
--user=user_name,userMySQL user name to use when connecting to server 

  • --help, -?

    Display a help message and exit.

  • --addtodest

    Do not rename target directory (if it exists); merely add files to it.

  • --allowold

    Do not abort if a target exists; rename it by adding an _old suffix.

  • --checkpoint=db_name.tbl_name

    Insert checkpoint entries into the specified database db_name and table tbl_name.

  • --chroot=path

    Base directory of the chroot jail in which mysqld operates. The path value should match that of the --chroot option given to mysqld.

  • --debug

    Enable debug output.

  • --dryrun, -n

    Report actions without performing them.

  • --flushlog

    Flush logs after all tables are locked.

  • --host=host_name, -h host_name

    The host name of the local host to use for making a TCP/IP connection to the local server. By default, the connection is made to localhost using a Unix socket file.

  • --keepold

    Do not delete previous (renamed) target when done.

  • --method=command

    The method for copying files (cp or scp). The default is cp.

  • --noindices

    Do not include full index files for MyISAM tables in the backup. This makes the backup smaller and faster. The indexes for reloaded tables can be reconstructed later with myisamchk -rq.

  • --password=password, -ppassword

    The password to use when connecting to the server. The password value is not optional for this option, unlike for other MySQL programs.

    Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, "End-User Guidelines for Password Security". You can use an option file to avoid giving the password on the command line.

  • --port=port_num, -P port_num

    The TCP/IP port number to use when connecting to the local server.

  • --old_server

    As of MySQL 5.5.3, mysqlhotcopy uses FLUSH TABLES tbl_list WITH READ LOCK to flush and lock tables. Use the --old_server option if the server is older than 5.5.3, which is when that statement was introduced. This option was added in MySQL 5.5.3.

  • --quiet, -q

    Be silent except for errors.

  • --record_log_pos=db_name.tbl_name

    Record master and slave status in the specified database db_name and table tbl_name.

  • --regexp=expr

    Copy all databases with names that match the given regular expression.

  • --resetmaster

    Reset the binary log after locking all the tables.

  • --resetslave

    Reset the master.info file after locking all the tables.

  • --socket=path, -S path

    The Unix socket file to use for connections to localhost.

  • --suffix=str

    The suffix to use for names of copied databases.

  • --tmpdir=path

    The temporary directory. The default is /tmp.

  • --user=user_name, -u user_name

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

Use perldoc for additional mysqlhotcopy documentation, including information about the structure of the tables needed for the --checkpoint and --record_log_pos options:

shell> perldoc mysqlhotcopy

4.6.10. mysql_convert_table_format - Convert Tables to Use a Given StorageEngine

mysql_convert_table_format converts the tables in a database to use a particular storage engine (MyISAM by default). mysql_convert_table_format is written in Perl and requires that the DBI and DBD::mysql Perl modules be installed (see Section 2.14, "Perl Installation Notes").

Invoke mysql_convert_table_format like this:

shell> mysql_convert_table_format [options]db_name

The db_name argument indicates the database containing the tables to be converted.

mysql_convert_table_format supports the options described in the following list.

  • --help

    Display a help message and exit.

  • --force

    Continue even if errors occur.

  • --host=host_name

    Connect to the MySQL server on the given host.

  • --password=password

    The password to use when connecting to the server. Note that the password value is not optional for this option, unlike for other MySQL programs.

    Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, "End-User Guidelines for Password Security". You can use an option file to avoid giving the password on the command line.

  • --port=port_num

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

  • --socket=path

    For connections to localhost, the Unix socket file to use.

  • --type=engine_name

    Specify the storage engine that the tables should be converted to use. The default is MyISAM if this option is not given.

  • --user=user_name

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

  • --verbose

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

  • --version

    Display version information and exit.

4.6.11. mysql_find_rows - Extract SQL Statements from Files

mysql_find_rows reads files containing SQL statements and extracts statements that match a given regular expression or that contain USE db_name or SET statements. The utility expects statements to be terminated with semicolon (;) characters.

Invoke mysql_find_rows like this:

shell> mysql_find_rows [options] [file_name ...]

Each file_name argument should be the name of file containing SQL statements. If no file names are given, mysql_find_rows reads the standard input.

Examples:

mysql_find_rows --regexp=problem_table --rows=20 < update.logmysql_find_rows --regexp=problem_table  update-log.1 update-log.2

mysql_find_rows supports the following options:

4.6.12. mysql_fix_extensions - Normalize Table File Name Extensions

mysql_fix_extensions converts the extensions for MyISAM (or ISAM) table files to their canonical forms. It looks for files with extensions matching any lettercase variant of .frm, .myd, .myi, .isd, and .ism and renames them to have extensions of .frm, .MYD, .MYI, .ISD, and .ISM, respectively. This can be useful after transferring the files from a system with case-insensitive file names (such as Windows) to a system with case-sensitive file names.

Invoke mysql_fix_extensions like this, where data_dir is the path name to the MySQL data directory.

shell> mysql_fix_extensions data_dir

4.6.13. mysql_setpermission - Interactively Set Permissions in GrantTables

mysql_setpermission is a Perl script that was originally written and contributed by Luuk de Boer. It interactively sets permissions in the MySQL grant tables. mysql_setpermission is written in Perl and requires that the DBI and DBD::mysql Perl modules be installed (see Section 2.14, "Perl Installation Notes").

Invoke mysql_setpermission like this:

shell> mysql_setpermission [options]

options should be either --help to display the help message, or options that indicate how to connect to the MySQL server. The account used when you connect determines which permissions you have when attempting to modify existing permissions in the grant tables.

mysql_setpermissions also reads options from the [client] and [perl] groups in the .my.cnf file in your home directory, if the file exists.

mysql_setpermission supports the following options:

4.6.14. mysql_waitpid - Kill Process and Wait for Its Termination

mysql_waitpid signals a process to terminate and waits for the process to exit. It uses the kill() system call and Unix signals, so it runs on Unix and Unix-like systems.

Invoke mysql_waitpid like this:

shell> mysql_waitpid [options] pid wait_time

mysql_waitpid sends signal 0 to the process identified by pid and waits up to wait_time seconds for the process to terminate. pid and wait_time must be positive integers.

If process termination occurs within the wait time or the process does not exist, mysql_waitpid returns 0. Otherwise, it returns 1.

If the kill() system call cannot handle signal 0, mysql_waitpid() uses signal 1 instead.

mysql_waitpid supports the following options:

  • --help, -?, -I

    Display a help message and exit.

  • --verbose, -v

    Verbose mode. Display a warning if signal 0 could not be used and signal 1 is used instead.

  • --version, -V

    Display version information and exit.

4.6.15. mysql_zap - Kill Processes That Match a Pattern

mysql_zap kills processes that match a pattern. It uses the ps command and Unix signals, so it runs on Unix and Unix-like systems.

Invoke mysql_zap like this:

shell> mysql_zap [-signal] [-?Ift] pattern

A process matches if its output line from the ps command contains the pattern. By default, mysql_zap asks for confirmation for each process. Respond y to kill the process, or q to exit mysql_zap. For any other response, mysql_zap does not attempt to kill the process.

If the -signal option is given, it specifies the name or number of the signal to send to each process. Otherwise, mysql_zap tries first with TERM (signal 15) and then with KILL (signal 9).

mysql_zap supports the following additional options:

  • --help, -?, -I

    Display a help message and exit.

  • -f

    Force mode. mysql_zap attempts to kill each process without confirmation.

  • -t

    Test mode. Display information about each process but do not kill it.

4.7. MySQL Program Development Utilities

This section describes some utilities that you may find useful when developing MySQL programs.

In shell scripts, you can use the my_print_defaults program to parse option files and see what options would be used by a given program. The following example shows the output that my_print_defaults might produce when asked to show the options found in the [client] and [mysql] groups:

shell> my_print_defaults client mysql--port=3306--socket=/tmp/mysql.sock--no-auto-rehash

Note for developers: Option file handling is implemented in the C client library simply by processing all options in the appropriate group or groups before any command-line arguments. This works well for programs that use the last instance of an option that is specified multiple times. If you have a C or C++ program that handles multiply specified options this way but that doesn't read option files, you need add only two lines to give it that capability. Check the source code of any of the standard MySQL clients to see how to do this.

Several other language interfaces to MySQL are based on the C client library, and some of them provide a way to access option file contents. These include Perl and Python. For details, see the documentation for your preferred interface.

4.7.1. msql2mysql - Convert mSQL Programs for Use with MySQL

Initially, the MySQL C API was developed to be very similar to that for the mSQL database system. Because of this, mSQL programs often can be converted relatively easily for use with MySQL by changing the names of the C API functions.

The msql2mysql utility performs the conversion of mSQL C API function calls to their MySQL equivalents. msql2mysql converts the input file in place, so make a copy of the original before converting it. For example, use msql2mysql like this:

shell> cp client-prog.c client-prog.c.origshell> msql2mysql client-prog.cclient-prog.c converted

Then examine client-prog.c and make any post-conversion revisions that may be necessary.

msql2mysql uses the replace utility to make the function name substitutions. See Section 4.8.2, "replace - A String-Replacement Utility".

4.7.2. mysql_config - Get Compile Options for Compiling Clients

mysql_config provides you with useful information for compiling your MySQL client and connecting it to MySQL.

mysql_config supports the following options.

  • --cflags

    Compiler flags to find include files and critical compiler flags and defines used when compiling the libmysqlclient library. The options returned are tied to the specific compiler that was used when the library was created and might clash with the settings for your own compiler. Use --include for more portable options that contain only include paths.

  • --include

    Compiler options to find MySQL include files.

  • --libmysqld-libs, --embedded

    Libraries and options required to link with the MySQL embedded server.

  • --libs

    Libraries and options required to link with the MySQL client library.

  • --libs_r

    Libraries and options required to link with the thread-safe MySQL client library.

  • --plugindir

    The default plugin directory path name, defined when configuring MySQL.

  • --port

    The default TCP/IP port number, defined when configuring MySQL.

  • --socket

    The default Unix socket file, defined when configuring MySQL.

  • --version

    Version number for the MySQL distribution.

If you invoke mysql_config with no options, it displays a list of all options that it supports, and their values:

shell> mysql_configUsage: /usr/local/mysql/bin/mysql_config [options]Options:  --cflags [-I/usr/local/mysql/include/mysql -mcpu=pentiumpro]  --include [-I/usr/local/mysql/include/mysql]  --libs   [-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto]  --libs_r [-L/usr/local/mysql/lib/mysql -lmysqlclient_r -lpthread -lz -lcrypt -lnsl -lm -lpthread]  --socket [/tmp/mysql.sock]  --port   [3306]  --version [4.0.16]  --libmysqld-libs [-L/usr/local/mysql/lib/mysql -lmysqld -lpthread -lz -lcrypt -lnsl -lm -lpthread -lrt]

You can use mysql_config within a command line to include the value that it displays for a particular option. For example, to compile a MySQL client program, use mysql_config as follows:

shell> CFG=/usr/local/mysql/bin/mysql_configshell> sh -c "gcc -o progname `$CFG --include` progname.c `$CFG --libs`"

When you use mysql_config this way, be sure to invoke it within backtick ("`") characters. That tells the shell to execute it and substitute its output into the surrounding command.

4.7.3. my_print_defaults - Display Options from Option Files

my_print_defaults displays the options that are present in option groups of option files. The output indicates what options will be used by programs that read the specified option groups. For example, the mysqlcheck program reads the [mysqlcheck] and [client] option groups. To see what options are present in those groups in the standard option files, invoke my_print_defaults like this:

shell> my_print_defaults mysqlcheck client--user=myusername--password=secret--host=localhost

The output consists of options, one per line, in the form that they would be specified on the command line.

my_print_defaults supports the following options.

4.7.4. resolve_stack_dump - Resolve Numeric Stack Trace Dump to Symbols

resolve_stack_dump resolves a numeric stack dump to symbols.

Invoke resolve_stack_dump like this:

shell> resolve_stack_dump [options] symbols_file [numeric_dump_file]

The symbols file should include the output from the nm --numeric-sort mysqld command. The numeric dump file should contain a numeric stack track from mysqld. If no numeric dump file is named on the command line, the stack trace is read from the standard input.

resolve_stack_dump supports the following options.

4.8. Miscellaneous Programs

4.8.1. perror - Explain Error Codes

For most system errors, MySQL displays, in addition to an internal text message, the system error code in one of the following styles:

message ... (errno: #)message ... (Errcode: #)

You can find out what the error code means by examining the documentation for your system or by using the perror utility.

perror prints a description for a system error code or for a storage engine (table handler) error code.

Invoke perror like this:

shell> perror [options] errorcode ...

Example:

shell> perror 13 64OS error code  13:  Permission deniedOS error code  64:  Machine is not on the network

To obtain the error message for a MySQL Cluster error code, invoke perror with the --ndb option:

shell> perror --ndb errorcode

Note that the meaning of system error messages may be dependent on your operating system. A given error code may mean different things on different operating systems.

perror supports the following options.

  • --help, --info, -I, -?

    Display a help message and exit.

  • --ndb

    Print the error message for a MySQL Cluster error code.

  • --silent, -s

    Silent mode. Print only the error message.

  • --verbose, -v

    Verbose mode. Print error code and message. This is the default behavior.

  • --version, -V

    Display version information and exit.

4.8.2. replace - A String-Replacement Utility

The replace utility program changes strings in place in files or on the standard input.

Invoke replace in one of the following ways:

shell> replace from to [from to] ... -- file_name [file_name] ...shell> replace from to [from to] ... < file_name

from represents a string to look for and to represents its replacement. There can be one or more pairs of strings.

Use the -- option to indicate where the string-replacement list ends and the file names begin. In this case, any file named on the command line is modified in place, so you may want to make a copy of the original before converting it. replace prints a message indicating which of the input files it actually modifies.

If the -- option is not given, replace reads the standard input and writes to the standard output.

replace uses a finite state machine to match longer strings first. It can be used to swap strings. For example, the following command swaps a and b in the given files, file1 and file2:

shell> replace a b b a -- file1 file2 ...

The replace program is used by msql2mysql. See Section 4.7.1, "msql2mysql - Convert mSQL Programs for Use with MySQL".

replace supports the following options.

  • -?, -I

    Display a help message and exit.

  • -#debug_options

    Enable debugging.

  • -s

    Silent mode. Print less information what the program does.

  • -v

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

  • -V

    Display version information and exit.

4.8.3. resolveip - Resolve Host name to IP Address or ViceVersa

The resolveip utility resolves host names to IP addresses and vice versa.

Invoke resolveip like this:

shell> resolveip [options] {host_name|ip-addr} ...

resolveip supports the following options.

  • --help, --info, -?, -I

    Display a help message and exit.

  • --silent, -s

    Silent mode. Produce less output.

  • --version, -V

    Display version information and exit.

Copyright © 1997, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
(Sebelumnya) 4.5. MySQL Client Programs5. MySQL Server Administration (Berikutnya)