innochecksum Command in Linux



The innochecksum command in Linux displays checksums for InnoDB files. InnoDB is a MySQL and MariaDB storage engine that supports transactions, row-level locking, foreign keys, and crash recovery, making it ideal for high-performance databases.

The innochecksum command examines the InnoDB tablespace file, computes a checksum for each page, checks it against the stored checksum, and identifies any mismatches. It is designed to verify the integrity of the tablespace after an issue.

Note − The innochecksum command will not display a checksum for an opened file. If the checksum is found, the tablespace is restored using the backup.

Table of Contents

Here is a comprehensive guide to the options available with the innochecksum command −

Prerequisites to Use innochecksum Command

The innochecksum is a part of MySQL or MariaDB. To use it, ensure either MariaDB or MySQL servers are installed on Linux.

To check whether the innochecksum command is installed or not on Linux, use the following command −

innochecksum --version
innochecksum Command in Linux1

To ensure the InnoDB is configured, use the following query in the MariaDB interactive session −

SHOW ENGINES;
innochecksum Command in Linux2

Understanding InnoDB Tablespace File

Upon installing MySQL or MariaDB a default InnoDB tablespace file is generated in the /var/lib/mysql directory with the name ibdata1. However, modifying the configuration file can also create a separate tablespace.

By default, the table data will be stored in the ibdata1 file. It is recommended to use a separate file. To configure the InnoDB to use separate files, the innodb_file_per_table option needs to be enabled in the configuration file. To enable it, open the 50-server configuration file using the following command −

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add the following line under the [msqld] −

innodb_file_per_table=ON
innochecksum Command in Linux3

Save and exit the file. Finally, restart the service to apply the changes.

sudo systemctl restart mariadb

Now, the InnoDB tables will be separately stored with .ibd extension. These files will be stored at the /var/lib/mysql/<database>/<table>.ibd.

Note − This configuration is for MariaDB.

Syntax of innochecksum Command

The syntax of the Linux innochecksum command is as follows −

innochecksum [options] [file]

The [options] field is used to specify the [options] and [file] is used to specify the InnoDB files.

Options of innochecksum Command

The options of the innochecksum command are listed below −

Flags Options Description
-a num --allow-mismatch= num Allows specified mismatches (maximum)
-c --count Displays the number of pages in a file
-D name --dump= name Dumps the page type info to a tablespace
-e num --end-page= num Ends at specified page number
-i --per-page-details Displays per page details
-I --info Displays command information
-f --leaf Examines the leaf index pages
-l name --log= name Logs the output to the specified file
-m num --merge= num Specifies the number of consecutive leaf pages to merge if the given number is provided
-n --no-check Ignores checksum verification
-p num --page= num Checks specified page
-s num --start-page= num Starts from the specified page
-S --page-type-summary Display a count of each page type in a tablespace
-v --verbose Displays verbose output
-V --version Displays command version
-w --write Rewrites the checksum
-? --help Displays command help (similar to -I or --info)

Examples of innochecksum Command in Linux

This section demonstrates the usage of the innochecksum command in Linux with examples −

Verifying Checksums

To verify the checksum, invoke the innochecksum command with the InnoDB file name −

innochecksum /var/lib/mysql/mydatabase/mytable.ibd

Displaying Page Count

To display the number of pages, use the -c or --count option −

sudo innochecksum -c /var/lib/mysql/mydatabase/mytable.ibd
innochecksum Command in Linux4

Displaying Page Types

To display the page types, use the -S or --page-type-summary option −

sudo innochecksum -S /var/lib/mysql/mydatabase/mytable.ibd
innochecksum Command in Linux5

Getting Verbose Output

To display the verbose output, use the -v or --verbose option −

sudo innochecksum -v -S /var/lib/mysql/mydatabase/mytable.ibd

Displaying Command Information

To display the command information, use the -I or --info option −

sudo innochecksum -I /var/lib/mysql/mydatabase/mytable.ibd

Note that this option is equivalent to the -? or --help option.

Logging the Output

To log the output to a file, use the -l or --log option with the file name. For example, to log the output to a file named file.log in the home directory, use the innochecksum command in the following way −

sudo innochecksum -l ~/file.log /var/lib/mysql/mydatabase/mytable.ibd
innochecksum Command in Linux6

Conclusion

The innochecksum command in Linux is essential for verifying the integrity of InnoDB tablespace files in MySQL and MariaDB environments. By calculating and comparing checksums, it helps identify any potential issues that could compromise data integrity.

Before using the innochecksum tool, ensure that it is correctly installed and configured, particularly with the innodb_file_per_table setting for optimal storage management. The system administrators use various options, such as displaying page counts and types, to maintain the reliability and performance of the systems.

In this tutorial, we explained the innochecksum command, its installation, syntax, options, and usage in Linux with examples.

Advertisements