MySQL Tutorials - Herong's Tutorial Examples
∟Storage Engines in MySQL Server
∟What Is InnoDB Storage Engine
This section describes the InnoDB storage engine, the default storage engine in the newer versions of MySQL server.
What InnoDB Storage Engine -
InnoDB Storage Engine is a general-purpose storage engine
that balances high reliability and high performance.
InnoDB storage engine is the default storage engine
in the newer versions of MySQL server.
Key advantages of InnoDB storage engine:
- Its DML operations follow the ACID model, with transactions featuring commit,
rollback, and crash-recovery capabilities to protect user data.
- Row-level locking and Oracle-style consistent reads increase multi-user
concurrency and performance.
- InnoDB tables arrange your data on disk to optimize queries based on primary
keys. Each InnoDB table has a primary key index called the clustered index that
organizes the data to minimize I/O for primary key lookups.
- To maintain data integrity, InnoDB supports FOREIGN KEY constraints. With
foreign keys, inserts, updates, and deletes are checked to ensure they do not
result in inconsistencies across related tables.
InnoDB storage engine has the following benefits:
- If the server unexpectedly exits because of a hardware or
software issue, regardless of what was happening in the
database at the time, you don't need to do anything special
after restarting the database. InnoDB crash
recovery automatically finalizes changes that were committed
before the time of the crash, and undoes changes that were in
process but not committed, permitting you to restart and
continue from where you left off.
- The InnoDB storage engine maintains its own
buffer pool that caches table and index data in main memory as
data is accessed. Frequently used data is processed directly
from memory. This cache applies to many types of information
and speeds up processing. On dedicated database servers, up to
80% of physical memory is often assigned to the buffer pool.
- If you split up related data into different tables, you can
set up foreign keys that enforce referential integrity.
- If data becomes corrupted on disk or in memory, a checksum
mechanism alerts you to the bogus data before you use it. The
innodb_checksum_algorithm variable defines the checksum algorithm used by
InnoDB.
- When you design a database with appropriate primary key
columns for each table, operations involving those columns are
automatically optimized. It is very fast to reference the
primary key columns in
WHERE clauses, ORDER
BY clauses,
GROUP BY clauses, and join operations.
- Inserts, updates, and deletes are optimized by an automatic
mechanism called change buffering. InnoDB
not only allows concurrent read and write access to the same
table, it caches changed data to streamline disk I/O.
- Performance benefits are not limited to large tables with
long-running queries. When the same rows are accessed over and
over from a table, the Adaptive Hash Index takes over to make
these lookups even faster, as if they came out of a hash
table.
- You can compress tables and associated indexes.
- You can encrypt your data.
- You can create and drop indexes and perform other DDL
operations with much less impact on performance and
availability.
- Truncating a file-per-table tablespace is very fast and can
free up disk space for the operating system to reuse rather
than only InnoDB.
- The storage layout for table data is more efficient for
BLOB and long text fields, with
the DYNAMIC row format.
- You can monitor the internal workings of the storage engine by
querying INFORMATION_SCHEMA tables.
- You can monitor the performance details of the storage engine
by querying Performance Schema tables.
- You can mix InnoDB tables with tables from
other MySQL storage engines, even within the same statement.
For example, you can use a join operation to combine data from
InnoDB and
MEMORY tables in a single query.
- InnoDB has been designed for CPU efficiency
and maximum performance when processing large data volumes.
- InnoDB tables can handle large quantities
of data, even on operating systems where file size is limited
to 2GB.
Best practices for InnoDB storage engine provided in
MySQL reference manual:
- Specify a primary key for every table using the most frequently queried column
or columns, or an auto-increment value if there is no obvious primary key.
- Use joins wherever data is pulled from multiple tables based on identical ID
values from those tables. For fast join performance, define foreign keys on the
join columns, and declare those columns with the same data type in each table.
Adding foreign keys ensures that referenced columns are indexed, which can
improve performance. Foreign keys also propagate deletes and updates to all
affected tables, and prevent insertion of data in a child table if the
corresponding IDs are not present in the parent table.
- Turn off autocommit. Committing hundreds of times a second puts a cap on
performance (limited by the write speed of your storage device).
- Group sets of related DML operations into transactions by bracketing them with
START TRANSACTION and COMMIT statements. While you don't want to commit too
often, you also don't want to issue huge batches of INSERT, UPDATE, or DELETE
statements that run for hours without committing.
- Do not use LOCK TABLES statements. InnoDB can handle multiple sessions all
reading and writing to the same table at once without sacrificing reliability or
high performance. To get exclusive write access to a set of rows, use the SELECT
... FOR UPDATE syntax to lock just the rows you intend to update.
- Enable the innodb_file_per_table variable or use general tablespaces to put the
data and indexes for tables into separate files instead of the system
tablespace. The innodb_file_per_table variable is enabled by default.
- Evaluate whether your data and access patterns benefit from the InnoDB table or
page compression features. You can compress InnoDB tables without sacrificing
read/write capability.
- Run the server with the --sql_mode=NO_ENGINE_SUBSTITUTION option to prevent
tables from being created with storage engines that you do not want to use.
Table of Contents
About This Book
Introduction of SQL
MySQL Introduction and Installation
Introduction of MySQL Programs
PHP Programs and MySQL Server
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Datatypes and Data Literals
Operations and Expressions
Character Strings and Bit Strings
Commonly Used Functions
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Locks Used in MySQL
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
MySQL Server Administration
►Storage Engines in MySQL Server
What Are Storage Engines
►What Is InnoDB Storage Engine
Convert Table to InnoDB Storage Engine
Clustered Index Used by InnoDB Engine
Statistic Information on InnoDB Tables
MySQL Status Variables for InnoDB Engine
MySQL System Variables for InnoDB Engine
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Bulk Changes on Large Tables
MySQL Server on macOS
Installing MySQL Server on Linux
Connection, Performance and Second Instance on Linux
Archived Tutorials
References
Full Version in PDF/EPUB