mysql 5.7 reference manual - including mysql cluster ndb 7.5

5426
MySQL 5.7 Reference Manual Including MySQL NDB Cluster 7.5 and NDB Cluster 7.6

Upload: nguyenhanh

Post on 28-Dec-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

MySQL 5.7 Reference Manual - Including MySQL NDB Cluster 7.5 and NDB Cluster 7.6Abstract
This is the MySQL™ Reference Manual. It documents MySQL 5.7 through 5.7.22, as well as NDB Cluster releases based on version 7.5 of NDB through 5.7.21-ndb-7.5.10, respectively.
MySQL 5.7 features. This manual describes features that are not included in every edition of MySQL 5.7; such features may not be included in the edition of MySQL 5.7 licensed to you. If you have any questions about the features included in your edition of MySQL 5.7, refer to your MySQL 5.7 license agreement or contact your Oracle sales representative.
For notes detailing the changes in each release, see the MySQL 5.7 Release Notes.
For legal information, see the Legal Notices.
For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists, where you can discuss your issues with other MySQL users.
For additional documentation on MySQL products, including translations of the documentation into other languages, and downloadable versions in variety of formats, including HTML and PDF formats, see the MySQL Documentation Library.
Licensing information—MySQL 5.7. This product may include third-party software, used under license. If you are using a Commercial release of MySQL 5.7, see this document for licensing information, including licensing information relating to third-party software that may be included in this Commercial release. If you are using a Community release of MySQL 5.7, see this document for licensing information, including licensing information relating to third-party software that may be included in this Community release.
Licensing information—MySQL NDB Cluster 7.5. This product may include third-party software, used under license. If you are using a Commercial release of NDB Cluster 7.5, see the MySQL NDB Cluster 7.5 Commercial Release License Information User Manual for licensing information relating to third-party software that may be included in this Commercial release. If you are using a Community release of NDB Cluster 7.5, see the MySQL NDB Cluster 7.5 Community Release License Information User Manual for licensing information relating to third-party software that may be included in this Community release.
Licensing information—MySQL NDB Cluster 7.6. If you are using a Developer Preview release of NDB Cluster 7.6, see the MySQL NDB Cluster 7.6 Community Release License Information User Manual for licensing information relating to third-party software that may be included in this Community release.
Document generated on: 2018-01-31 (revision: 55783)
Table of Contents Preface and Legal Notices ............................................................................................................. xxvii 1 General Information ......................................................................................................................... 1
1.1 About This Manual ............................................................................................................... 2 1.2 Typographical and Syntax Conventions ................................................................................. 3 1.3 Overview of the MySQL Database Management System ........................................................ 4
1.3.1 What is MySQL? ....................................................................................................... 4 1.3.2 The Main Features of MySQL .................................................................................... 6 1.3.3 History of MySQL ...................................................................................................... 9
1.4 What Is New in MySQL 5.7 .................................................................................................. 9 1.5 Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 5.7 ....... 24 1.6 MySQL Information Sources ............................................................................................... 32
1.6.1 MySQL Websites ..................................................................................................... 32 1.6.2 MySQL Mailing Lists ................................................................................................ 32 1.6.3 MySQL Community Support at the MySQL Forums ................................................... 35 1.6.4 MySQL Community Support on Internet Relay Chat (IRC) .......................................... 35 1.6.5 MySQL Enterprise .................................................................................................... 35
1.7 How to Report Bugs or Problems ........................................................................................ 36 1.8 MySQL Standards Compliance ............................................................................................ 40
1.8.1 MySQL Extensions to Standard SQL ........................................................................ 41 1.8.2 MySQL Differences from Standard SQL .................................................................... 44 1.8.3 How MySQL Deals with Constraints ......................................................................... 46
1.9 Credits ............................................................................................................................... 50 1.9.1 Contributors to MySQL ............................................................................................. 50 1.9.2 Documenters and translators .................................................................................... 54 1.9.3 Packages that support MySQL ................................................................................. 56 1.9.4 Tools that were used to create MySQL ..................................................................... 56 1.9.5 Supporters of MySQL .............................................................................................. 57
2 Installing and Upgrading MySQL .................................................................................................... 59 2.1 General Installation Guidance ............................................................................................. 61
2.1.1 Which MySQL Version and Distribution to Install ....................................................... 62 2.1.2 How to Get MySQL ................................................................................................. 63 2.1.3 Verifying Package Integrity Using MD5 Checksums or GnuPG ................................... 63 2.1.4 Installation Layouts .................................................................................................. 78 2.1.5 Compiler-Specific Build Characteristics ..................................................................... 78
2.2 Installing MySQL on Unix/Linux Using Generic Binaries ........................................................ 78 2.3 Installing MySQL on Microsoft Windows .............................................................................. 82
2.3.1 MySQL Installation Layout on Microsoft Windows ...................................................... 85 2.3.2 Choosing an Installation Package ............................................................................. 85 2.3.3 MySQL Installer for Windows ................................................................................... 86 2.3.4 MySQL Notifier ...................................................................................................... 106 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive ................. 117 2.3.6 Troubleshooting a Microsoft Windows MySQL Server Installation .............................. 126 2.3.7 Windows Postinstallation Procedures ...................................................................... 128 2.3.8 Upgrading MySQL on Windows .............................................................................. 130 2.3.9 Deploying MySQL on Windows and Other Non-Linux Platforms ................................ 132
2.4 Installing MySQL on OS X ................................................................................................ 132 2.4.1 General Notes on Installing MySQL on OS X .......................................................... 132 2.4.2 Installing MySQL on OS X Using Native Packages .................................................. 133 2.4.3 Installing a MySQL Launch Daemon ....................................................................... 139 2.4.4 Installing and Using the MySQL Preference Pane .................................................... 142
2.5 Installing MySQL on Linux ................................................................................................ 147
MySQL 5.7 Reference Manual
iv
2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository .................................. 148 2.5.2 Replacing a Third-Party Distribution of MySQL Using the MySQL Yum Repository ..... 152 2.5.3 Installing MySQL on Linux Using the MySQL APT Repository ................................... 155 2.5.4 Installing MySQL on Linux Using the MySQL SLES Repository ................................. 155 2.5.5 Installing MySQL on Linux Using RPM Packages from Oracle .................................. 155 2.5.6 Installing MySQL on Linux Using Debian Packages from Oracle ............................... 161 2.5.7 Deploying MySQL on Linux with Docker .................................................................. 162 2.5.8 Installing MySQL on Linux from the Native Software Repositories ............................. 170 2.5.9 Installing MySQL on Linux with Juju ....................................................................... 173 2.5.10 Managing MySQL Server with systemd ................................................................. 173
2.6 Installing MySQL Using Unbreakable Linux Network (ULN) ................................................. 179 2.7 Installing MySQL on Solaris .............................................................................................. 179
2.7.1 Installing MySQL on Solaris Using a Solaris PKG .................................................... 180 2.8 Installing MySQL on FreeBSD ........................................................................................... 181 2.9 Installing MySQL from Source ........................................................................................... 182
2.9.1 MySQL Layout for Source Installation ..................................................................... 184 2.9.2 Installing MySQL Using a Standard Source Distribution ............................................ 184 2.9.3 Installing MySQL Using a Development Source Tree ............................................... 189 2.9.4 MySQL Source-Configuration Options ..................................................................... 191 2.9.5 Dealing with Problems Compiling MySQL ................................................................ 213 2.9.6 MySQL Configuration and Third-Party Tools ............................................................ 214
2.10 Postinstallation Setup and Testing ................................................................................... 214 2.10.1 Initializing the Data Directory ................................................................................ 215 2.10.2 Starting the Server ............................................................................................... 223 2.10.3 Testing the Server ................................................................................................ 226 2.10.4 Securing the Initial MySQL Accounts .................................................................... 228 2.10.5 Starting and Stopping MySQL Automatically .......................................................... 232
2.11 Upgrading or Downgrading MySQL .................................................................................. 233 2.11.1 Upgrading MySQL ................................................................................................ 234 2.11.2 Downgrading MySQL ........................................................................................... 251 2.11.3 Rebuilding or Repairing Tables or Indexes ............................................................ 258 2.11.4 Copying MySQL Databases to Another Machine .................................................... 260
2.12 Perl Installation Notes ..................................................................................................... 261 2.12.1 Installing Perl on Unix .......................................................................................... 261 2.12.2 Installing ActiveState Perl on Windows .................................................................. 262 2.12.3 Problems Using the Perl DBI/DBD Interface .......................................................... 263
3 Tutorial ........................................................................................................................................ 265 3.1 Connecting to and Disconnecting from the Server .............................................................. 265 3.2 Entering Queries ............................................................................................................... 266 3.3 Creating and Using a Database ........................................................................................ 269
3.3.1 Creating and Selecting a Database ......................................................................... 271 3.3.2 Creating a Table .................................................................................................... 271 3.3.3 Loading Data into a Table ...................................................................................... 273 3.3.4 Retrieving Information from a Table ........................................................................ 274
3.4 Getting Information About Databases and Tables ............................................................... 288 3.5 Using mysql in Batch Mode .............................................................................................. 289 3.6 Examples of Common Queries .......................................................................................... 290
3.6.1 The Maximum Value for a Column ......................................................................... 291 3.6.2 The Row Holding the Maximum of a Certain Column ............................................... 291 3.6.3 Maximum of Column per Group .............................................................................. 292 3.6.4 The Rows Holding the Group-wise Maximum of a Certain Column ............................ 292 3.6.5 Using User-Defined Variables ................................................................................. 293 3.6.6 Using Foreign Keys ................................................................................................ 293 3.6.7 Searching on Two Keys ......................................................................................... 295
MySQL 5.7 Reference Manual
3.6.8 Calculating Visits Per Day ...................................................................................... 295 3.6.9 Using AUTO_INCREMENT ..................................................................................... 296
3.7 Using MySQL with Apache ............................................................................................... 298 4 MySQL Programs ........................................................................................................................ 301
4.1 Overview of MySQL Programs .......................................................................................... 302 4.2 Using MySQL Programs ................................................................................................... 306
4.2.1 Invoking MySQL Programs ..................................................................................... 306 4.2.2 Connecting to the MySQL Server ........................................................................... 307 4.2.3 Specifying Program Options ................................................................................... 311 4.2.4 Using Options on the Command Line ..................................................................... 312 4.2.5 Program Option Modifiers ....................................................................................... 313 4.2.6 Using Option Files ................................................................................................. 314 4.2.7 Command-Line Options that Affect Option-File Handling .......................................... 319 4.2.8 Using Options to Set Program Variables ................................................................. 320 4.2.9 Option Defaults, Options Expecting Values, and the = Sign ...................................... 321 4.2.10 Setting Environment Variables .............................................................................. 325
4.3 MySQL Server and Server-Startup Programs ..................................................................... 326 4.3.1 mysqld — The MySQL Server ............................................................................... 326 4.3.2 mysqld_safe — MySQL Server Startup Script ...................................................... 326 4.3.3 mysql.server — MySQL Server Startup Script .................................................... 333 4.3.4 mysqld_multi — Manage Multiple MySQL Servers ............................................... 335
4.4 MySQL Installation-Related Programs ................................................................................ 339 4.4.1 comp_err — Compile MySQL Error Message File .................................................. 339 4.4.2 mysql_install_db — Initialize MySQL Data Directory ......................................... 340 4.4.3 mysql_plugin — Configure MySQL Server Plugins .............................................. 351 4.4.4 mysql_secure_installation — Improve MySQL Installation Security ................ 353 4.4.5 mysql_ssl_rsa_setup — Create SSL/RSA Files ................................................. 356 4.4.6 mysql_tzinfo_to_sql — Load the Time Zone Tables ......................................... 359 4.4.7 mysql_upgrade — Check and Upgrade MySQL Tables ......................................... 359
4.5 MySQL Client Programs ................................................................................................... 367 4.5.1 mysql — The MySQL Command-Line Tool ............................................................ 367 4.5.2 mysqladmin — Client for Administering a MySQL Server ....................................... 394 4.5.3 mysqlcheck — A Table Maintenance Program ...................................................... 403 4.5.4 mysqldump — A Database Backup Program .......................................................... 411 4.5.5 mysqlimport — A Data Import Program ............................................................... 433 4.5.6 mysqlpump — A Database Backup Program .......................................................... 440 4.5.7 mysqlsh — The MySQL Shell ............................................................................... 456 4.5.8 mysqlshow — Display Database, Table, and Column Information ............................ 460 4.5.9 mysqlslap — Load Emulation Client ..................................................................... 465
4.6 MySQL Administrative and Utility Programs ....................................................................... 474 4.6.1 innochecksum — Offline InnoDB File Checksum Utility .......................................... 474 4.6.2 myisam_ftdump — Display Full-Text Index information .......................................... 480 4.6.3 myisamchk — MyISAM Table-Maintenance Utility .................................................. 481 4.6.4 myisamlog — Display MyISAM Log File Contents .................................................. 498 4.6.5 myisampack — Generate Compressed, Read-Only MyISAM Tables ........................ 499 4.6.6 mysql_config_editor — MySQL Configuration Utility ......................................... 505 4.6.7 mysqlbinlog — Utility for Processing Binary Log Files .......................................... 512 4.6.8 mysqldumpslow — Summarize Slow Query Log Files ............................................ 534
4.7 MySQL Program Development Utilities .............................................................................. 536 4.7.1 mysql_config — Display Options for Compiling Clients ........................................ 536 4.7.2 my_print_defaults — Display Options from Option Files .................................... 538 4.7.3 resolve_stack_dump — Resolve Numeric Stack Trace Dump to Symbols ............. 539
4.8 Miscellaneous Programs ................................................................................................... 540 4.8.1 lz4_decompress — Decompress mysqlpump LZ4-Compressed Output .................. 540
MySQL 5.7 Reference Manual
vi
4.8.2 perror — Explain Error Codes ............................................................................. 540 4.8.3 replace — A String-Replacement Utility ................................................................ 541 4.8.4 resolveip — Resolve Host name to IP Address or Vice Versa .............................. 542 4.8.5 zlib_decompress — Decompress mysqlpump ZLIB-Compressed Output ............... 542
4.9 MySQL Program Environment Variables ............................................................................ 543 5 MySQL Server Administration ...................................................................................................... 547
5.1 The MySQL Server ........................................................................................................... 548 5.1.1 Configuring the Server ........................................................................................... 548 5.1.2 Server Configuration Defaults ................................................................................. 550 5.1.3 Server Option and Variable Reference .................................................................... 550 5.1.4 Server Command Options ...................................................................................... 596 5.1.5 Server System Variables ........................................................................................ 634 5.1.6 Using System Variables ......................................................................................... 785 5.1.7 Server Status Variables .......................................................................................... 804 5.1.8 Server SQL Modes ................................................................................................ 840 5.1.9 IPv6 Support .......................................................................................................... 858 5.1.10 Server-Side Help .................................................................................................. 862 5.1.11 Server Response to Signals ................................................................................. 863 5.1.12 The Server Shutdown Process ............................................................................. 864
5.2 The MySQL Data Directory ............................................................................................... 865 5.3 The mysql System Database ............................................................................................. 866 5.4 MySQL Server Logs ......................................................................................................... 868
5.4.1 Selecting General Query and Slow Query Log Output Destinations ........................... 869 5.4.2 The Error Log ........................................................................................................ 871 5.4.3 The General Query Log ......................................................................................... 874 5.4.4 The Binary Log ...................................................................................................... 876 5.4.5 The Slow Query Log .............................................................................................. 887 5.4.6 The DDL Log ......................................................................................................... 889 5.4.7 Server Log Maintenance ........................................................................................ 889
5.5 MySQL Server Plugins ...................................................................................................... 891 5.5.1 Installing and Uninstalling Plugins ........................................................................... 892 5.5.2 Obtaining Server Plugin Information ........................................................................ 896 5.5.3 MySQL Enterprise Thread Pool .............................................................................. 897 5.5.4 The Rewriter Query Rewrite Plugin ......................................................................... 904 5.5.5 Version Tokens ...................................................................................................... 912
5.6 Running Multiple MySQL Instances on One Machine .......................................................... 925 5.6.1 Setting Up Multiple Data Directories ........................................................................ 926 5.6.2 Running Multiple MySQL Instances on Windows ..................................................... 927 5.6.3 Running Multiple MySQL Instances on Unix ............................................................ 930 5.6.4 Using Client Programs in a Multiple-Server Environment .......................................... 932
5.7 Tracing mysqld Using DTrace ........................................................................................... 932 5.7.1 mysqld DTrace Probe Reference ............................................................................ 934
6 Security ....................................................................................................................................... 953 6.1 General Security Issues .................................................................................................... 954
6.1.1 Security Guidelines ................................................................................................ 954 6.1.2 Keeping Passwords Secure .................................................................................... 956 6.1.3 Making MySQL Secure Against Attackers ............................................................... 965 6.1.4 Security-Related mysqld Options and Variables ....................................................... 966 6.1.5 How to Run MySQL as a Normal User ................................................................... 967 6.1.6 Security Issues with LOAD DATA LOCAL ............................................................... 968 6.1.7 Client Programming Security Guidelines .................................................................. 969
6.2 The MySQL Access Privilege System ................................................................................ 971 6.2.1 Privileges Provided by MySQL ............................................................................... 972 6.2.2 Grant Tables .......................................................................................................... 977
MySQL 5.7 Reference Manual
vii
6.2.3 Specifying Account Names ..................................................................................... 983 6.2.4 Access Control, Stage 1: Connection Verification ..................................................... 985 6.2.5 Access Control, Stage 2: Request Verification ......................................................... 988 6.2.6 When Privilege Changes Take Effect ...................................................................... 989 6.2.7 Troubleshooting Problems Connecting to MySQL .................................................... 990
6.3 MySQL User Account Management ................................................................................... 995 6.3.1 User Names and Passwords .................................................................................. 995 6.3.2 Adding User Accounts ............................................................................................ 997 6.3.3 Removing User Accounts ....................................................................................... 999 6.3.4 Reserved User Accounts ........................................................................................ 999 6.3.5 Setting Account Resource Limits ............................................................................ 999 6.3.6 Assigning Account Passwords .............................................................................. 1002 6.3.7 Password Management ........................................................................................ 1003 6.3.8 Password Expiration and Sandbox Mode .............................................................. 1005 6.3.9 Pluggable Authentication ...................................................................................... 1007 6.3.10 Proxy Users ....................................................................................................... 1009 6.3.11 User Account Locking ......................................................................................... 1015 6.3.12 SQL-Based MySQL Account Activity Auditing ...................................................... 1016
6.4 Using Encrypted Connections .......................................................................................... 1017 6.4.1 Configuring MySQL to Use Encrypted Connections ................................................ 1019 6.4.2 Command Options for Encrypted Connections ....................................................... 1023 6.4.3 Creating SSL and RSA Certificates and Keys ........................................................ 1028 6.4.4 OpenSSL Versus yaSSL ...................................................................................... 1037 6.4.5 Building MySQL with Support for Encrypted Connections ....................................... 1037 6.4.6 Encrypted Connection Protocols and Ciphers ........................................................ 1038 6.4.7 Connecting to MySQL Remotely from Windows with SSH ...................................... 1042
6.5 Security Plugins .............................................................................................................. 1042 6.5.1 Authentication Plugins .......................................................................................... 1043 6.5.2 The Connection-Control Plugins ............................................................................ 1097 6.5.3 The Password Validation Plugin ............................................................................ 1103 6.5.4 The MySQL Keyring ............................................................................................. 1110 6.5.5 MySQL Enterprise Audit ....................................................................................... 1143 6.5.6 MySQL Enterprise Firewall ................................................................................... 1209
7 Backup and Recovery ................................................................................................................ 1223 7.1 Backup and Recovery Types ........................................................................................... 1224 7.2 Database Backup Methods .............................................................................................. 1227 7.3 Example Backup and Recovery Strategy ......................................................................... 1229
7.3.1 Establishing a Backup Policy ................................................................................ 1230 7.3.2 Using Backups for Recovery ................................................................................. 1232 7.3.3 Backup Strategy Summary ................................................................................... 1232
7.4 Using mysqldump for Backups ........................................................................................ 1233 7.4.1 Dumping Data in SQL Format with mysqldump ...................................................... 1233 7.4.2 Reloading SQL-Format Backups ........................................................................... 1234 7.4.3 Dumping Data in Delimited-Text Format with mysqldump ....................................... 1235 7.4.4 Reloading Delimited-Text Format Backups ............................................................ 1236 7.4.5 mysqldump Tips ................................................................................................... 1237
7.5 Point-in-Time (Incremental) Recovery Using the Binary Log .............................................. 1239 7.5.1 Point-in-Time Recovery Using Event Times ........................................................... 1241 7.5.2 Point-in-Time Recovery Using Event Positions ....................................................... 1241
7.6 MyISAM Table Maintenance and Crash Recovery ............................................................ 1242 7.6.1 Using myisamchk for Crash Recovery ................................................................... 1242 7.6.2 How to Check MyISAM Tables for Errors .............................................................. 1243 7.6.3 How to Repair MyISAM Tables ............................................................................. 1244 7.6.4 MyISAM Table Optimization .................................................................................. 1246
MySQL 5.7 Reference Manual
viii
7.6.5 Setting Up a MyISAM Table Maintenance Schedule ............................................... 1247 8 Optimization .............................................................................................................................. 1249
8.1 Optimization Overview ..................................................................................................... 1250 8.2 Optimizing SQL Statements ............................................................................................ 1252
8.2.1 Optimizing SELECT Statements ............................................................................ 1252 8.2.2 Optimizing Subqueries, Derived Tables, and View References ................................ 1298 8.2.3 Optimizing INFORMATION_SCHEMA Queries ...................................................... 1310 8.2.4 Optimizing Data Change Statements ..................................................................... 1315 8.2.5 Optimizing Database Privileges ............................................................................. 1316 8.2.6 Other Optimization Tips ........................................................................................ 1317
8.3 Optimization and Indexes ................................................................................................ 1317 8.3.1 How MySQL Uses Indexes ................................................................................... 1318 8.3.2 Primary Key Optimization ..................................................................................... 1319 8.3.3 Foreign Key Optimization ..................................................................................... 1319 8.3.4 Column Indexes ................................................................................................... 1319 8.3.5 Multiple-Column Indexes ...................................................................................... 1321 8.3.6 Verifying Index Usage .......................................................................................... 1322 8.3.7 InnoDB and MyISAM Index Statistics Collection ..................................................... 1322 8.3.8 Comparison of B-Tree and Hash Indexes .............................................................. 1324 8.3.9 Use of Index Extensions ....................................................................................... 1326 8.3.10 Optimizer Use of Generated Column Indexes ...................................................... 1328
8.4 Optimizing Database Structure ........................................................................................ 1330 8.4.1 Optimizing Data Size ............................................................................................ 1330 8.4.2 Optimizing MySQL Data Types ............................................................................. 1332 8.4.3 Optimizing for Many Tables .................................................................................. 1334 8.4.4 Internal Temporary Table Use in MySQL ............................................................... 1335
8.5 Optimizing for InnoDB Tables .......................................................................................... 1337 8.5.1 Optimizing Storage Layout for InnoDB Tables ........................................................ 1337 8.5.2 Optimizing InnoDB Transaction Management ........................................................ 1338 8.5.3 Optimizing InnoDB Read-Only Transactions .......................................................... 1339 8.5.4 Optimizing InnoDB Redo Logging ......................................................................... 1340 8.5.5 Bulk Data Loading for InnoDB Tables ................................................................... 1340 8.5.6 Optimizing InnoDB Queries .................................................................................. 1342 8.5.7 Optimizing InnoDB DDL Operations ...................................................................... 1342 8.5.8 Optimizing InnoDB Disk I/O .................................................................................. 1342 8.5.9 Optimizing InnoDB Configuration Variables ............................................................ 1345 8.5.10 Optimizing InnoDB for Systems with Many Tables ................................................ 1347
8.6 Optimizing for MyISAM Tables ........................................................................................ 1347 8.6.1 Optimizing MyISAM Queries ................................................................................. 1347 8.6.2 Bulk Data Loading for MyISAM Tables .................................................................. 1348 8.6.3 Optimizing REPAIR TABLE Statements ................................................................ 1350
8.7 Optimizing for MEMORY Tables ...................................................................................... 1351 8.8 Understanding the Query Execution Plan ......................................................................... 1352
8.8.1 Optimizing Queries with EXPLAIN ......................................................................... 1352 8.8.2 EXPLAIN Output Format ...................................................................................... 1353 8.8.3 Extended EXPLAIN Output Format ....................................................................... 1366 8.8.4 Obtaining Execution Plan Information for a Named Connection ............................... 1368 8.8.5 Estimating Query Performance ............................................................................. 1369
8.9 Controlling the Query Optimizer ....................................................................................... 1370 8.9.1 Controlling Query Plan Evaluation ......................................................................... 1370 8.9.2 Optimizer Hints .................................................................................................... 1370 8.9.3 Switchable Optimizations ...................................................................................... 1377 8.9.4 Index Hints .......................................................................................................... 1380 8.9.5 The Optimizer Cost Model .................................................................................... 1383
MySQL 5.7 Reference Manual
ix
8.10 Buffering and Caching ................................................................................................... 1386 8.10.1 InnoDB Buffer Pool Optimization ......................................................................... 1386 8.10.2 The MyISAM Key Cache .................................................................................... 1387 8.10.3 The MySQL Query Cache .................................................................................. 1391 8.10.4 Caching of Prepared Statements and Stored Programs ........................................ 1398
8.11 Optimizing Locking Operations ...................................................................................... 1400 8.11.1 Internal Locking Methods .................................................................................... 1400 8.11.2 Table Locking Issues .......................................................................................... 1402 8.11.3 Concurrent Inserts .............................................................................................. 1404 8.11.4 Metadata Locking ............................................................................................... 1404 8.11.5 External Locking ................................................................................................. 1405
8.12 Optimizing the MySQL Server ....................................................................................... 1406 8.12.1 System Factors .................................................................................................. 1406 8.12.2 Optimizing Disk I/O ............................................................................................ 1407 8.12.3 Using Symbolic Links ......................................................................................... 1408 8.12.4 Optimizing Memory Use ..................................................................................... 1411 8.12.5 Optimizing Network Use ..................................................................................... 1417
8.13 Measuring Performance (Benchmarking) ........................................................................ 1419 8.13.1 Measuring the Speed of Expressions and Functions ............................................ 1420 8.13.2 Using Your Own Benchmarks ............................................................................. 1420 8.13.3 Measuring Performance with performance_schema .............................................. 1420
8.14 Examining Thread Information ....................................................................................... 1421 8.14.1 Thread Command Values ................................................................................... 1422 8.14.2 General Thread States ....................................................................................... 1424 8.14.3 Query Cache Thread States ............................................................................... 1430 8.14.4 Replication Master Thread States ....................................................................... 1431 8.14.5 Replication Slave I/O Thread States .................................................................... 1431 8.14.6 Replication Slave SQL Thread States .................................................................. 1433 8.14.7 Replication Slave Connection Thread States ........................................................ 1433 8.14.8 NDB Cluster Thread States ................................................................................ 1434 8.14.9 Event Scheduler Thread States ........................................................................... 1435
9 Language Structure ................................................................................................................... 1437 9.1 Literal Values .................................................................................................................. 1437
9.1.1 String Literals ....................................................................................................... 1437 9.1.2 Numeric Literals ................................................................................................... 1440 9.1.3 Date and Time Literals ......................................................................................... 1440 9.1.4 Hexadecimal Literals ............................................................................................ 1443 9.1.5 Bit-Value Literals .................................................................................................. 1444 9.1.6 Boolean Literals ................................................................................................... 1446 9.1.7 NULL Values ....................................................................................................... 1446
9.2 Schema Object Names ................................................................................................... 1446 9.2.1 Identifier Qualifiers ............................................................................................... 1449 9.2.2 Identifier Case Sensitivity ..................................................................................... 1451 9.2.3 Mapping of Identifiers to File Names ..................................................................... 1453 9.2.4 Function Name Parsing and Resolution ................................................................. 1455
9.3 Keywords and Reserved Words ....................................................................................... 1459 9.4 User-Defined Variables ................................................................................................... 1484 9.5 Expression Syntax .......................................................................................................... 1487 9.6 Comment Syntax ............................................................................................................ 1489
10 Globalization ............................................................................................................................ 1491 10.1 Character Set Support ................................................................................................... 1491
10.1.1 Character Sets and Collations in General ............................................................ 1492 10.1.2 Character Sets and Collations in MySQL ............................................................. 1493 10.1.3 Specifying Character Sets and Collations ............................................................ 1497
MySQL 5.7 Reference Manual
x
10.1.4 Connection Character Sets and Collations ........................................................... 1508 10.1.5 Configuring Application Character Set and Collation ............................................. 1511 10.1.6 Error Message Character Set ............................................................................. 1513 10.1.7 Column Character Set Conversion ...................................................................... 1513 10.1.8 Collation Issues .................................................................................................. 1515 10.1.9 Unicode Support ................................................................................................ 1523 10.1.10 Supported Character Sets and Collations .......................................................... 1530
10.2 Setting the Error Message Language ............................................................................. 1545 10.3 Adding a Character Set ................................................................................................. 1546
10.3.1 Character Definition Arrays ................................................................................. 1548 10.3.2 String Collating Support for Complex Character Sets ............................................ 1549 10.3.3 Multi-Byte Character Support for Complex Character Sets .................................... 1549
10.4 Adding a Collation to a Character Set ............................................................................ 1549 10.4.1 Collation Implementation Types .......................................................................... 1550 10.4.2 Choosing a Collation ID ...................................................................................... 1553 10.4.3 Adding a Simple Collation to an 8-Bit Character Set ............................................. 1554 10.4.4 Adding a UCA Collation to a Unicode Character Set ............................................ 1555
10.5 Character Set Configuration .......................................................................................... 1562 10.6 MySQL Server Time Zone Support ................................................................................ 1563
10.6.1 Staying Current with Time Zone Changes ............................................................ 1566 10.6.2 Time Zone Leap Second Support ........................................................................ 1567
10.7 MySQL Server Locale Support ...................................................................................... 1569 11 Data Types .............................................................................................................................. 1573
11.1 Data Type Overview ..................................................................................................... 1574 11.1.1 Numeric Type Overview ..................................................................................... 1574 11.1.2 Date and Time Type Overview ............................................................................ 1577 11.1.3 String Type Overview ......................................................................................... 1579
11.2 Numeric Types .............................................................................................................. 1583 11.2.1 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT ......................................................................................................................... 1583 11.2.2 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC ...................................... 1584 11.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE .............................. 1584 11.2.4 Bit-Value Type - BIT ........................................................................................... 1585 11.2.5 Numeric Type Attributes ..................................................................................... 1585 11.2.6 Out-of-Range and Overflow Handling .................................................................. 1586
11.3 Date and Time Types ................................................................................................... 1588 11.3.1 The DATE, DATETIME, and TIMESTAMP Types ................................................. 1589 11.3.2 The TIME Type .................................................................................................. 1591 11.3.3 The YEAR Type ................................................................................................. 1591 11.3.4 YEAR(2) Limitations and Migrating to YEAR(4) .................................................... 1592 11.3.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME .................. 1595 11.3.6 Fractional Seconds in Time Values ..................................................................... 1598 11.3.7 Conversion Between Date and Time Types ......................................................... 1599 11.3.8 Two-Digit Years in Dates .................................................................................... 1600
11.4 String Types ................................................................................................................. 1601 11.4.1 The CHAR and VARCHAR Types ....................................................................... 1601 11.4.2 The BINARY and VARBINARY Types ................................................................. 1603 11.4.3 The BLOB and TEXT Types ............................................................................... 1604 11.4.4 The ENUM Type ................................................................................................ 1605 11.4.5 The SET Type ................................................................................................... 1609
11.5 Spatial Data Types ....................................................................................................... 1611 11.5.1 Spatial Data Types ............................................................................................. 1613 11.5.2 The OpenGIS Geometry Model ........................................................................... 1613 11.5.3 Supported Spatial Data Formats ......................................................................... 1619
MySQL 5.7 Reference Manual
11.5.4 Geometry Well-Formedness and Validity ............................................................. 1622 11.5.5 Creating Spatial Columns ................................................................................... 1623 11.5.6 Populating Spatial Columns ................................................................................ 1623 11.5.7 Fetching Spatial Data ......................................................................................... 1625 11.5.8 Optimizing Spatial Analysis ................................................................................. 1625 11.5.9 Creating Spatial Indexes ..................................................................................... 1625 11.5.10 Using Spatial Indexes ....................................................................................... 1626
11.6 The JSON Data Type ................................................................................................... 1628 11.7 Data Type Default Values ............................................................................................. 1642 11.8 Data Type Storage Requirements .................................................................................. 1643 11.9 Choosing the Right Type for a Column .......................................................................... 1647 11.10 Using Data Types from Other Database Engines .......................................................... 1648
12 Functions and Operators .......................................................................................................... 1649 12.1 Function and Operator Reference .................................................................................. 1651 12.2 Type Conversion in Expression Evaluation ..................................................................... 1664 12.3 Operators ..................................................................................................................... 1667
12.3.1 Operator Precedence ......................................................................................... 1668 12.3.2 Comparison Functions and Operators ................................................................. 1669 12.3.3 Logical Operators ............................................................................................... 1675 12.3.4 Assignment Operators ........................................................................................ 1677
12.4 Control Flow Functions .................................................................................................. 1678 12.5 String Functions ............................................................................................................ 1680
12.5.1 String Comparison Functions .............................................................................. 1697 12.5.2 Regular Expressions ........................................................................................... 1701 12.5.3 Character Set and Collation of Function Results .................................................. 1707
12.6 Numeric Functions and Operators .................................................................................. 1708 12.6.1 Arithmetic Operators ........................................................................................... 1709 12.6.2 Mathematical Functions ...................................................................................... 1711
12.7 Date and Time Functions .............................................................................................. 1721 12.8 What Calendar Is Used By MySQL? .............................................................................. 1744 12.9 Full-Text Search Functions ............................................................................................ 1744
12.9.1 Natural Language Full-Text Searches .................................................................. 1745 12.9.2 Boolean Full-Text Searches ................................................................................ 1749 12.9.3 Full-Text Searches with Query Expansion ............................................................ 1754 12.9.4 Full-Text Stopwords ............................................................................................ 1755 12.9.5 Full-Text Restrictions .......................................................................................... 1761 12.9.6 Fine-Tuning MySQL Full-Text Search .................................................................. 1762 12.9.7 Adding a Collation for Full-Text Indexing ............................................................. 1765 12.9.8 ngram Full-Text Parser ....................................................................................... 1766 12.9.9 MeCab Full-Text Parser Plugin ........................................................................... 1769
12.10 Cast Functions and Operators ..................................................................................... 1773 12.11 XML Functions ............................................................................................................ 1779 12.12 Bit Functions and Operators ........................................................................................ 1791 12.13 Encryption and Compression Functions ........................................................................ 1794 12.14 Information Functions .................................................................................................. 1803 12.15 Spatial Analysis Functions ........................................................................................... 1813
12.15.1 Spatial Function Reference ............................................................................... 1814 12.15.2 Argument Handling by Spatial Functions ............................................................ 1818 12.15.3 Functions That Create Geometry Values from WKT Values ................................ 1819 12.15.4 Functions That Create Geometry Values from WKB Values ................................ 1822 12.15.5 MySQL-Specific Functions That Create Geometry Values ................................... 1825 12.15.6 Geometry Format Conversion Functions ............................................................ 1826 12.15.7 Geometry Property Functions ............................................................................ 1827 12.15.8 Spatial Operator Functions ................................................................................ 1837
MySQL 5.7 Reference Manual
12.15.9 Functions That Test Spatial Relations Between Geometry Objects ...................... 1840 12.15.10 Spatial Geohash Functions ............................................................................. 1846 12.15.11 Spatial GeoJSON Functions ............................................................................ 1848 12.15.12 Spatial Convenience Functions ....................................................................... 1849
12.16 JSON Functions .......................................................................................................... 1852 12.16.1 JSON Function Reference ................................................................................ 1853 12.16.2 Functions That Create JSON Values ................................................................. 1854 12.16.3 Functions That Search JSON Values ................................................................ 1855 12.16.4 Functions That Modify JSON Values ................................................................. 1864 12.16.5 Functions That Return JSON Value Attributes .................................................... 1873 12.16.6 JSON Utility Functions ...................................................................................... 1876 12.16.7 JSON Path Syntax ........................................................................................... 1879
12.17 Functions Used with Global Transaction IDs ................................................................. 1880 12.18 MySQL Enterprise Encryption Functions ....................................................................... 1883
12.18.1 Enterprise Encryption Installation ....................................................................... 1883 12.18.2 Enterprise Encryption Usage and Examples ....................................................... 1884 12.18.3 Enterprise Encryption Function Reference ......................................................... 1886 12.18.4 Enterprise Encryption Function Descriptions ...................................................... 1887
12.19 Aggregate (GROUP BY) Functions .............................................................................. 1891 12.19.1 Aggregate (GROUP BY) Function Descriptions .................................................. 1891 12.19.2 GROUP BY Modifiers ....................................................................................... 1896 12.19.3 MySQL Handling of GROUP BY ....................................................................... 1900 12.19.4 Detection of Functional Dependence ................................................................. 1903
12.20 Miscellaneous Functions .............................................................................................. 1907 12.21 Precision Math ............................................................................................................ 1917
12.21.1 Types of Numeric Values .................................................................................. 1918 12.21.2 DECIMAL Data Type Characteristics ................................................................. 1918 12.21.3 Expression Handling ......................................................................................... 1919 12.21.4 Rounding Behavior ........................................................................................... 1921 12.21.5 Precision Math Examples .................................................................................. 1922
13 SQL Statement Syntax ............................................................................................................. 1927 13.1 Data Definition Statements ............................................................................................ 1928
13.1.1 ALTER DATABASE Syntax ................................................................................ 1928 13.1.2 ALTER EVENT Syntax ....................................................................................... 1929 13.1.3 ALTER FUNCTION Syntax ................................................................................. 1931 13.1.4 ALTER INSTANCE Syntax ................................................................................. 1932 13.1.5 ALTER LOGFILE GROUP Syntax ....................................................................... 1932 13.1.6 ALTER PROCEDURE Syntax ............................................................................. 1933 13.1.7 ALTER SERVER Syntax ..................................................................................... 1934 13.1.8 ALTER TABLE Syntax ........................................................................................ 1934 13.1.9 ALTER TABLESPACE Syntax ............................................................................ 1960 13.1.10 ALTER VIEW Syntax ........................................................................................ 1962 13.1.11 CREATE DATABASE Syntax ............................................................................ 1962 13.1.12 CREATE EVENT Syntax .................................................................................. 1962 13.1.13 CREATE FUNCTION Syntax ............................................................................ 1967 13.1.14 CREATE INDEX Syntax ................................................................................... 1967 13.1.15 CREATE LOGFILE GROUP Syntax .................................................................. 1972 13.1.16 CREATE PROCEDURE and CREATE FUNCTION Syntax ................................. 1974 13.1.17 CREATE SERVER Syntax ................................................................................ 1979 13.1.18 CREATE TABLE Syntax ................................................................................... 1981 13.1.19 CREATE TABLESPACE Syntax ........................................................................ 2025 13.1.20 CREATE TRIGGER Syntax .............................................................................. 2031 13.1.21 CREATE VIEW Syntax ..................................................................................... 2033 13.1.22 DROP DATABASE Syntax ................................................................................ 2038
MySQL 5.7 Reference Manual
xiii
13.1.23 DROP EVENT Syntax ...................................................................................... 2039 13.1.24 DROP FUNCTION Syntax ................................................................................ 2039 13.1.25 DROP INDEX Syntax ....................................................................................... 2039 13.1.26 DROP LOGFILE GROUP Syntax ...................................................................... 2040 13.1.27 DROP PROCEDURE and DROP FUNCTION Syntax ......................................... 2040 13.1.28 DROP SERVER Syntax .................................................................................... 2041 13.1.29 DROP TABLE Syntax ....................................................................................... 2041 13.1.30 DROP TABLESPACE Syntax ............................................................................ 2042 13.1.31 DROP TRIGGER Syntax .................................................................................. 2043 13.1.32 DROP VIEW Syntax ......................................................................................... 2043 13.1.33 RENAME TABLE Syntax .................................................................................. 2044 13.1.34 TRUNCATE TABLE Syntax .............................................................................. 2045
13.2 Data Manipulation Statements ....................................................................................... 2046 13.2.1 CALL Syntax ...................................................................................................... 2046 13.2.2 DELETE Syntax ................................................................................................. 2047 13.2.3 DO Syntax ......................................................................................................... 2052 13.2.4 HANDLER Syntax .............................................................................................. 2052 13.2.5 INSERT Syntax .................................................................................................. 2054 13.2.6 LOAD DATA INFILE Syntax ............................................................................... 2062 13.2.7 LOAD XML Syntax ............................................................................................. 2071 13.2.8 REPLACE Syntax ............................................................................................... 2079 13.2.9 SELECT Syntax ................................................................................................. 2082 13.2.10 Subquery Syntax .............................................................................................. 2098 13.2.11 UPDATE Syntax ............................................................................................... 2111
13.3 Transactional and Locking Statements ........................................................................... 2114 13.3.1 START TRANSACTION, COMMIT, and ROLLBACK Syntax ................................. 2114 13.3.2 Statements That Cannot Be Rolled Back ............................................................. 2117 13.3.3 Statements That Cause an Implicit Commit ......................................................... 2117 13.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Syntax ... 2118 13.3.5 LOCK TABLES and UNLOCK TABLES Syntax .................................................... 2119 13.3.6 SET TRANSACTION Syntax ............................................................................... 2125 13.3.7 XA Transactions ................................................................................................. 2127
13.4 Replication Statements .................................................................................................. 2130 13.4.1 SQL Statements for Controlling Master Servers ................................................... 2130 13.4.2 SQL Statements for Controlling Slave Servers ..................................................... 2133 13.4.3 SQL Statements for Controlling Group Replication ............................................... 2148
13.5 Prepared SQL Statement Syntax ................................................................................... 2149 13.5.1 PREPARE Syntax .............................................................................................. 2153 13.5.2 EXECUTE Syntax .............................................................................................. 2153 13.5.3 DEALLOCATE PREPARE Syntax ....................................................................... 2153
13.6 Compound-Statement Syntax ........................................................................................ 2154 13.6.1 BEGIN ... END Compound-Statement Syntax ...................................................... 2154 13.6.2 Statement Label Syntax ...................................................................................... 2154 13.6.3 DECLARE Syntax .............................................................................................. 2155 13.6.4 Variables in Stored Programs ............................................................................. 2156 13.6.5 Flow Control Statements ..................................................................................... 2157 13.6.6 Cursors .............................................................................................................. 2162 13.6.7 Condition Handling ............................................................................................. 2164
13.7 Database Administration Statements .............................................................................. 2192 13.7.1 Account Management Statements ....................................................................... 2192 13.7.2 Table Maintenance Statements ........................................................................... 2220 13.7.3 Plugin and User-Defined Function Statements ..................................................... 2231 13.7.4 SET Syntax ........................................................................................................ 2234 13.7.5 SHOW Syntax .................................................................................................... 2238
MySQL 5.7 Reference Manual
13.7.6 Other Administrative Statements ......................................................................... 2288 13.8 Utility Statements .......................................................................................................... 2299
13.8.1 DESCRIBE Syntax ............................................................................................. 2299 13.8.2 EXPLAIN Syntax ................................................................................................ 2299 13.8.3 HELP Syntax ..................................................................................................... 2301 13.8.4 USE Syntax ....................................................................................................... 2303
14 The InnoDB Storage Engine ..................................................................................................... 2305 14.1 Introduction to InnoDB ................................................................................................... 2307
14.1.1 Benefits of Using InnoDB Tables ........................................................................ 2308 14.1.2 Best Practices for InnoDB Tables ........................................................................ 2309 14.1.3 Checking InnoDB Availability .............................................................................. 2310 14.1.4 Testing and Benchmarking with InnoDB .............................................................. 2310 14.1.5 Turning Off InnoDB ............................................................................................ 2311
14.2 InnoDB and the ACID Model ......................................................................................... 2311 14.3 InnoDB Multi-Versioning ................................................................................................ 2312 14.4 InnoDB Architecture ...................................................................................................... 2313
14.4.1 Buffer Pool ......................................................................................................... 2314 14.4.2 Change Buffer .................................................................................................... 2314 14.4.3 Adaptive Hash Index .......................................................................................... 2316 14.4.4 Redo Log Buffer ................................................................................................. 2316 14.4.5 System Tablespace ............................................................................................ 2317 14.4.6 InnoDB Data Dictionary ...................................................................................... 2317 14.4.7 Doublewrite Buffer .............................................................................................. 2317 14.4.8 Undo Logs ......................................................................................................... 2317 14.4.9 File-Per-Table Tablespaces ................................................................................ 2318 14.4.10 General Tablespaces ........................................................................................ 2318 14.4.11 Undo Tablespace ............................................................................................. 2318 14.4.12 Temporary Tablespace ..................................................................................... 2319 14.4.13 Redo Log ......................................................................................................... 2319
14.5 InnoDB Locking and Transaction Model ......................................................................... 2320 14.5.1 InnoDB Locking .................................................................................................. 2320 14.5.2 InnoDB Transaction Model .................................................................................. 2325 14.5.3 Locks Set by Different SQL Statements in InnoDB ............................................... 2332 14.5.4 Phantom Rows ................................................................................................... 2335 14.5.5 Deadlocks in InnoDB .......................................................................................... 2336
14.6 InnoDB Configuration .................................................................................................... 2340 14.6.1 InnoDB Startup Configuration .............................................................................. 2340 14.6.2 Configuring InnoDB for Read-Only Operation ....................................................... 2346 14.6.3 InnoDB Buffer Pool Configuration ........................................................................ 2347 14.6.4 Configuring the Memory Allocator for InnoDB ...................................................... 2367 14.6.5 Configuring InnoDB Change Buffering ................................................................. 2368 14.6.6 Configuring Thread Concurrency for InnoDB ........................................................ 2370 14.6.7 Configuring the Number of Background InnoDB I/O Threads ................................. 2371 14.6.8 Using Asynchronous I/O on Linux ....................................................................... 2371 14.6.9 Configuring the InnoDB Master Thread I/O Rate .................................................. 2372 14.6.10 Configuring Spin Lock Polling ........................................................................... 2372 14.6.11 Configuring InnoDB Purge Scheduling ............................................................... 2373 14.6.12 Configuring Optimizer Statistics for InnoDB ........................................................ 2373 14.6.13 Configuring the Merge Threshold for Index Pages .............................................. 2385
14.7 InnoDB Tablespaces ..................................................................................................... 2387 14.7.1 Resizing the InnoDB System Tablespace ............................................................ 2388 14.7.2 Changing the Number or Size of InnoDB Redo Log Files ...................................... 2389 14.7.3 Using Raw Disk Partitions for the System Tablespace .......................................... 2389 14.7.4 InnoDB File-Per-Table Tablespaces .................................................................... 2391
MySQL 5.7 Reference Manual
14.7.5 Creating File-Per-Table Tablespaces Outside the Data Directory ........................... 2393 14.7.6 Copying File-Per-Table Tablespaces to Another Instance ..................................... 2395 14.7.7 Configuring Undo Tablespaces ........................................................................... 2402 14.7.8 Truncating Undo Tablespaces ............................................................................. 2403 14.7.9 InnoDB General Tablespaces ............................................................................. 2405 14.7.10 InnoDB Tablespace Encryption ......................................................................... 2412
14.8 InnoDB Tables and Indexes .......................................................................................... 2417 14.8.1 InnoDB Tables ................................................................................................... 2417 14.8.2 InnoDB Indexes ................................................................................................. 2441
14.9 InnoDB Table and Page Compression ........................................................................... 2449 14.9.1 InnoDB Table Compression ................................................................................ 2449 14.9.2 InnoDB Page Compression ................................................................................. 2464
14.10 InnoDB File-Format Management ................................................................................. 2467 14.10.1 Enabling File Formats ....................................................................................... 2468 14.10.2 Verifying File Format Compatibility .................................................................... 2468 14.10.3 Identifying the File Format in Use ...................................................................... 2472 14.10.4 Modifying the File Format ................................................................................. 2473
14.11 InnoDB Row Storage and Row Formats ....................................................................... 2473 14.11.1 Overview of InnoDB Row Storage ..................................................................... 2473 14.11.2 Specifying the Row Format for a Table .............................................................. 2473 14.11.3 DYNAMIC and COMPRESSED Row Formats .................................................... 2475 14.11.4 COMPACT and REDUNDANT Row Formats ..................................................... 2476
14.12 InnoDB Disk I/O and File Space Management .............................................................. 2477 14.12.1 InnoDB Disk I/O ............................................................................................... 2477 14.12.2 File Space Management ................................................................................... 2478 14.12.3 InnoDB Checkpoints ......................................................................................... 2479 14.12.4 Defragmenting a Table ..................................................................................... 2480 14.12.5 Reclaiming Disk Space with TRUNCATE TABLE ............................................... 2480
14.13 InnoDB and Online DDL .............................................................................................. 2481 14.13.1 Online DDL Overview ....................................................................................... 2481 14.13.2 Online DDL Performance, Concurrency, and Space Requirements ...................... 2487 14.13.3 Online DDL SQL Syntax ................................................................................... 2491 14.13.4 Simplifying DDL Statements with Online DDL .................................................... 2491 14.13.5 Online DDL Implementation Details ................................................................... 2492 14.13.6 Online DDL and Crash Recovery ...................................................................... 2493 14.13.7 Online DDL for Partitioned Tables ..................................................................... 2493 14.13.8 Online DDL Limitations ..................................................................................... 2495
14.14 InnoDB Startup Options and System Variables ............................................................. 2496 14.15 InnoDB INFORMATION_SCHEMA Tables .................................................................... 2585
14.15.1 InnoDB INFORMATION_SCHEMA Tables about Compression ........................... 2585 14.15.2 InnoDB INFORMATION_SCHEMA Transaction and Locking Information ............. 2587 14.15.3 InnoDB INFORMATION_SCHEMA System Tables ............................................. 2593 14.15.4 InnoDB INFORMATION_SCHEMA FULLTEXT Index Tables .............................. 2599 14.15.5 InnoDB INFORMATION_SCHEMA Buffer Pool Tables ........................................ 2602 14.15.6 InnoDB INFORMATION_SCHEMA Metrics Table ............................................... 2607 14.15.7 InnoDB INFORMATION_SCHEMA Temporary Table Info Table .......................... 2616 14.15.8 Retrieving InnoDB Tablespace Metadata from INFORMATION_SCHEMA.FILES .. 2617
14.16 InnoDB Integration with MySQL Performance Schema .................................................. 2619 14.16.1 Monitoring ALTER TABLE Progress for InnoDB Tables Using Performance Schema ........................................................................................................................ 2621 14.16.2 Monitoring InnoDB Mutex Waits Using Performance Schema .............................. 2622
14.17 InnoDB Monitors ......................................................................................................... 2626 14.17.1 InnoDB Monitor Types ...................................................................................... 2626 14.17.2 Enabling InnoDB Monitors ................................................................................ 2627
MySQL 5.7 Reference Manual
xvi
14.17.3 InnoDB Standard Monitor and Lock Monitor Output ............................................ 2628 14.18 InnoDB Backup and Recovery ..................................................................................... 2634
14.18.1 InnoDB Backup ................................................................................................ 2634 14.18.2 InnoDB Recovery ............................................................................................. 2635
14.19 InnoDB and MySQL Replication ................................................................................... 2638 14.20 InnoDB memcached Plugin .......................................................................................... 2640
14.20.1 Benefits of the InnoDB memcached Plugin ........................................................ 2640 14.20.2 InnoDB memcached Architecture ...................................................................... 2641 14.20.3 Setting Up the InnoDB memcached Plugin ........................................................ 2645 14.20.4 Security Considerations for the InnoDB memcached Plugin ................................ 2651 14.20.5 Writing Applications for the InnoDB memcached Plugin ...................................... 2653 14.20.6 The InnoDB memcached Plugin and Replication ................................................ 2666 14.20.7 InnoDB memcached Plugin Internals ................................................................. 2670 14.20.8 Troubleshooting the InnoDB memcached Plugin ................................................ 2674
14.21 InnoDB Troubleshooting .............................................................................................. 2676 14.21.1 Troubleshooting InnoDB I/O Problems ............................................................... 2677 14.21.2 Forcing InnoDB Recovery ................................................................................. 2678 14.21.3 Troubleshooting InnoDB Data Dictionary Operations .......................................... 2679 14.21.4 InnoDB Error Handling ...................................................................................... 2683
15 Alternative Storage Engines ..................................................................................................... 2685 15.1 Setting the Storage Engine ............................................................................................ 2689 15.2 The MyISAM Storage Engine ........................................................................................ 2689
15.2.1 MyISAM Startup Options .................................................................................... 2692 15.2.2 Space Needed for Keys ..................................................................................... 2693 15.2.3 MyISAM Table Storage Formats ......................................................................... 2694 15.2.4 MyISAM Table Problems .................................................................................... 2696
15.3 The MEMORY Storage Engine ...................................................................................... 2698 15.4 The CSV Storage Engine ........