以下提供给 mysqld 的选项可以用来更改 MyISAM 表的行为。有关更多信息,请参见 第 7.1.7 节,“服务器命令选项”。The following options to mysqld can be used to
change the behavior of MyISAM tables. For
additional information, see Section 7.1.7, “Server Command Options”.
表 18.3 MyISAM 选项及变量参考Table 18.3 MyISAM Option and Variable Reference
| 名称Name | 命令行Cmd-Line | 选项文件Option File | 系统变量System Var | 状态变量Status Var | 变量范围Var Scope | 动态Dynamic |
|---|---|---|---|---|---|---|
| 批量插入缓冲区大小bulk_insert_buffer_size | 是Yes | 是Yes | 是Yes | 两者Both | 是Yes | |
| 并发插入concurrent_insert | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| 延迟关键字写入delay_key_write | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| 支持 R 树键have_rtree_keys | 是Yes | 全球Global | 否No | |||
| key_buffer_size(键缓冲区大小)key_buffer_size | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| ISAM 日志log-isam | 是Yes | 是Yes | ||||
| MyISAM 块大小myisam-block-size | 是Yes | 是Yes | ||||
| myisam_data_pointer_size | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| myisam_max_sort_file_size | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| myisam_mmap_size | 是Yes | 是Yes | 是Yes | 全球Global | 否No | |
| myisam_recover_options | 是Yes | 是Yes | 是Yes | 全球Global | 否No | |
| myisam_sort_buffer_size | 是Yes | 是Yes | 是Yes | 两者Both | 是Yes | |
| myisam_stats_method | 是Yes | 是Yes | 是Yes | 两者Both | 是Yes | |
| myisam_use_mmap | 是Yes | 是Yes | 是Yes | 全球Global | 是Yes | |
| tmp_table_size(临时表大小)tmp_table_size | 是Yes | 是Yes | 是Yes | 两者Both | 是Yes |
以下系统变量会影响 MyISAM 表的行为。有关更多信息,请参见 第 7.1.8 节,“服务器系统变量”。The following system variables affect the behavior of
MyISAM tables. For additional information, see
Section 7.1.8, “Server System Variables”.
用于批量插入优化的树缓存大小。The size of the tree cache used in bulk insert optimization.
Note这是每个 线程 的限制!This is a limit per thread!
在对任何
MyISAM表进行写入时,不刷新键缓冲区。Don't flush key buffers between writes for anyMyISAMtable.Note如果你这样做,在表正在使用时,不应从另一个程序访问
MyISAM表(例如从另一个 MySQL 服务器或使用 myisamchk)。这样做有索引损坏的风险。使用--external-locking并不能消除此风险。If you do this, you should not accessMyISAMtables from another program (such as from another MySQL server or with myisamchk) when the tables are in use. Doing so risks index corruption. Using--external-lockingdoes not eliminate this risk.MySQL 在重新创建
MyISAM索引时(在REPAIR TABLE、ALTER TABLE或LOAD DATA时)允许使用的临时文件的最大大小。如果文件大小超过此值,则索引将改用键缓存创建,这会更慢。该值以字节为单位。The maximum size of the temporary file that MySQL is permitted to use while re-creating aMyISAMindex (duringREPAIR TABLE,ALTER TABLE, orLOAD DATA). If the file size would be larger than this value, the index is created using the key cache instead, which is slower. The value is given in bytes.设置自动恢复崩溃的
MyISAM表的模式。Set the mode for automatic recovery of crashedMyISAMtables.设置恢复表时使用的缓冲区大小。Set the size of the buffer used when recovering tables.
如果在启动 mysqld 时设置了 myisam_recover_options 系统变量,则会激活自动恢复。在这种情况下,当服务器打开 MyISAM 表时,它会检查表是否被标记为崩溃,或者表的打开计数变量是否不为 0,并且服务器以禁用外部锁的方式运行。如果上述任一条件为真,将发生以下情况:Automatic recovery is activated if you start
mysqld with the
myisam_recover_options system
variable set. In this case, when the server opens a
MyISAM table, it checks whether the table is
marked as crashed or whether the open count variable for the table
is not 0 and you are running the server with external locking
disabled. If either of these conditions is true, the following
happens:
服务器检查表是否存在错误。The server checks the table for errors.
如果服务器发现错误,它会尝试快速表修复(带排序但不重新创建数据文件)。If the server finds an error, it tries to do a fast table repair (with sorting and without re-creating the data file).
如果由于数据文件中的错误(例如重复键错误)而修复失败,服务器会再次尝试,这次会重新创建数据文件。If the repair fails because of an error in the data file (for example, a duplicate-key error), the server tries again, this time re-creating the data file.
如果修复仍然失败,服务器会再次尝试使用旧的修复选项方法(逐行写入而不排序)。这种方法应该能够修复任何类型的错误,并且所需磁盘空间较低。If the repair still fails, the server tries once more with the old repair option method (write row by row without sorting). This method should be able to repair any type of error and has low disk space requirements.
如果恢复无法从先前已完成的语句中恢复所有行,并且您没有在 myisam_recover_options 系统变量的值中指定 FORCE,自动修复将中止并在错误日志中显示错误消息:If the recovery wouldn't be able to recover all rows from
previously completed statements and you didn't specify
FORCE in the value of the
myisam_recover_options system
variable, automatic repair aborts with an error message in the
error log:
Error: Couldn't repair table: test.g00pages
如果你指定了 FORCE,会写入如下警告:If you specify FORCE, a warning like this is
written instead:
Warning: Found 344 of 354 rows when repairing ./test/g00pages
如果自动恢复值包括 BACKUP,恢复过程会创建名称形式为 的文件。你应该有一个 cron 脚本,自动将这些文件从数据库目录移动到备份媒介。If the automatic recovery value includes
tbl_name-datetime.BAKBACKUP, the recovery process creates files with
names of the form
.
You should have a cron script that
automatically moves these files from the database directories to
backup media.tbl_name-datetime.BAK