环境:CentOS6.5,Percona Server 5.6.25,Xtrabackup 1.5.1
描述:备份失败,报错
Error executing 'LOCK TABLES FOR BACKUP': DBD::mysql::db do failed: The MySQL server is running with the delay_key_write=ALL option so it cannot execute this statement at /usr/bin/innobackupex line 3052
原因&解决:
50.6 MyISAM index and data buffering
MyISAM key buffering is normally write-through, i.e. by the time each update to a MyISAM table is completed, all index updates are written to disk. The only exception is delayed key writing feature which is disabled by default.
When the global system variable delay_key_write is set to ALL, key buffers for all MyISAM tables are not flushed between updates, so a physical backup of those tables may result in broken MyISAM indexes. To prevent this, LOCK TABLES FOR BACKUP will fail with an error if delay_key_write is set to ALL. An attempt to set delay_key_write to ALL when there’s an active backup lock will also fail with an error.
Another option to involve delayed key writing is to create MyISAM tables with the DELAY_KEY_WRITE option and set the delay_key_write variable to ON (which is the default). In this case, LOCK TABLES FOR BACKUP will not be able to prevent stale index files from appearing in the backup. Users are encouraged to set delay_key_writes to OFF in the configuration file, my.cnf, or repair MyISAM indexes after restoring from a physical backup created with backup locks.
MyISAM may also cache data for bulk inserts, e.g. when executing multi-row INSERTs or LOAD DATA statements.
Those caches, however, are flushed between statements, so have no effect on physical backups as long as all statements updating MyISAM tables are blocked.
——来源Percona Server 5.6.33-79.0官方文档
 
一般情况下,myisam表会在表数据刷盘时也将索引刷盘,但是设置delay_key_write参数为ALL后,myisam会在表关闭时才将索引刷盘。如果此时做物理备份会导致myisam表的索引损坏。为了避免这种事情发生,LOCK TABLES FOR BACKUP会失败并报错。
delay_key_write默认情况下会被设成ON,这种情况下,LOCK TABLES FOR BACKUP不会阻止备份获取当前已经过期的索引。建议用户在配置文件中将delay_key_write设为OFF,或者恢复数据后修复索引。