MySQL DELAY_KEY_WRITE Option
This option applies only to MyISAM tables. It can have one of the following values to affect handling of the DELAY_KEY_WRITE table option that can be used in CREATE TABLE statements.
If DELAY_KEY_WRITE is enabled for a table, the key buffer is not flushed for the table on every index update, but only when the table is closed. This speeds up writes on keys a lot, but if you use this feature, you should add automatic checking of all MyISAM tables by starting the server with the --myisam-recover-options option (for example, --myisam-recover-options=BACKUP,FORCE). See Section 5.1.3, “Server Command Options”, and Section 14.4.1, “MyISAM Startup Options”.
Another performance option in MySQL is the DELAY_KEY_WRITE option. According to the MySQL documentation the option makes index updates faster because they are not flushed to disk until the table is closed.
Note that this option applies only to MyISAM tables,
You can enable it on a table by table basis using the following SQL statement:
ALTER TABLE sometable DELAY_KEY_WRITE = 1;
This can also be set in the advanced table options in the MySQL Query Browser.
This performance option could be handy if you have to do a lot of update, because you can delay writing the indexes until tables are closed. So frequent updates to large tables, may want to check out this option.
Ok, so when does MySQL close tables?
That should have been your next question. It looks as though tables are opened when they are needed, but then added to the table cache. This cache can be flushed manually with FLUSH TABLES; but here's how they are closed automatically according to the docs:
- When the cache is full and a thread tries to open a table that is not in the cache.
- When the cache contains more than
table_cacheentries and a thread is no longer using a table. FLUSH TABLES;is called.
If
DELAY_KEY_WRITEis enabled, this means that the key buffer for tables with this option are not flushed on every index update, but only when a table is closed. This speeds up writes on keys a lot, but if you use this feature, you should add automatic checking of all MyISAM tables by starting the server with the--myisam-recoveroption (for example,--myisam-recover=BACKUP,FORCE).
So if you do use this option you may want to flush your table cache periodically, and make sure you startup using the myisam-recover option.
注:
delay_key_write这个参数只对myisam类型表有效
如果你某个表需要经常update操作,这个参数就很管用!
但等delay_key_write使用时,出现断电或重启时,会导致在cache的索引update没来得及更新,所以必须在启动参数加上
–myisam-recover,或者在conf设置myisam-recover=BACKUP,FORCE。这样在你启动mysql的时候会检查你的
表并同步表和索引.
另外如果修复myisam类表可以在my.cnf中mysqld段设置myisam-recover恢复功能,参数有:default,force,backup,QUICK
1.
LOCK TABLES `test` WRITE;
ALTER TABLE `test` DISABLE KEYS ;
INSERT
INTO `test` VALUES
(1,'???',80,1),(2,'???',90,2),(1,'李四',80,3),(2,'王五',90,4),(1,'aa',12,5),
(3,'aa',123,6),(4,'aadwa',123,7);
ALTER TABLE `test` ENABLE KEYS;
UNLOCK TABLES;
2.
当cache 满了一个新的thread试图打开一个表的时候,那个表没有在cache;
当cache里的表数比table_cache多时thread不在使用表;
这个2种情况将会flush table。
当delay_key_write 使用的时候,如果出现重启或者掉电等情况,会导致在cache的索引update没来得及更新,所以必须在启动参数加上--myisam-recover,或者在conf设置myisam-recover=BACKUP,FORCE。这样在你启动mysql的时候会检查你的表并同步表和索引.
常用MySQL的童鞋都知道这个myisam类型的表极容易损坏,多数人可能都是用myisamchk命令来人工修复,下面介绍一种自动修复myisam的方法,也是我上午刚学的,共同进步,呵呵~
在MySQL的配置文件my.cnf中,启动项部分加入myisam-recover设置数据恢复功能,具体参数如下:
DEFAULT
与没有使用--myisam-recover选项相同。
BACKUP
如果在恢复过程中,数据文件被更改了,将tbl_name.MYD文件备份为tbl_name-datetime.BAK。
FORCE
即使.MYD文件将丢掉多个行也进行恢复。
QUICK
如果没有删除块,不要检查表中的行。
我设置了BACKUP和FORCE参数,如下:
[mysqld]
myisam-recover=BACKUP,FORCE
参考:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_delay_key_write
http://www.petefreitag.com/item/441.cfm
http://www.cnblogs.com/zhizhesky/archive/2011/08/22/2149357.html
MySQL DELAY_KEY_WRITE Option的更多相关文章
- mysql 有没有参数都报错“mysql: unknown option”
报错: [root@XXXX tmp]# mysql -uroot -pmysql: unknown option '--You have new mail in /var/spool/mail/ro ...
- mysql 常用option
[mysql 常用option] --host=host_name, -h host_name Connect to the MySQL server on the given host. --por ...
- Mysql –>EF edmx(model first)–> Sql server table
一.mysql environment When we create an new database,first We need draw er diagram for somebody to sho ...
- Spark:将DataFrame写入Mysql
Spark将DataFrame进行一些列处理后,需要将之写入mysql,下面是实现过程 1.mysql的信息 mysql的信息我保存在了外部的配置文件,这样方便后续的配置添加. //配置文件示例: [ ...
- Spark:读取mysql数据作为DataFrame
在日常工作中,有时候需要读取mysql的数据作为DataFrame数据源进行后期的Spark处理,Spark自带了一些方法供我们使用,读取mysql我们可以直接使用表的结构信息,而不需要自己再去定义每 ...
- 在oracle配置mysql数据库的dblink
本文介绍如何在oracle配置mysql数据库的dblink:虽然dblink使用很占资源:俗称“性能杀手”.但有些场景不得不使用它.例如公司使用数据库是oracle:可能其他部门或者CP合作公司使用 ...
- Mysql 5.6 MHA (gtid) on Kylin
mha on Kylinip hostname repl role mha role192.168.19.69 mysql1 master node192.168.19.73 mysql2 slave ...
- MySQL/MariaDB数据库的主主复制
MySQL/MariaDB数据库的主主复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主主复制概述 1>.什么是主主复制 所谓的主主复制,说白了就是两台节点互为 ...
- MySQL SSL配置(mysql5.7和mysql5.6)
专题一:mysql5.7上开启并配置ssl [root@mysqlmaster01 bin]# ./mysql_ssl_rsa_setup --datadir=/data/mysql_data1/ - ...
随机推荐
- YUM工具使用
一.yum命令概述: 1.简介: yum命令时在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载R ...
- Spyder在windows下常用快捷键
块注释/反块注释:Ctrl+4/5 行注释/反行注释:Ctrl+1 代码提示:Tab 复制一行:Ctrl+Alt+↓/↑ 删除一行:Ctrl+D 运行:F5 全屏:F11 撤销:Ctrl+Z 反撤销: ...
- 【Android】下拉刷新实现
关于这方面的文章百度下有很多,我就只写写我自己实现过程. 我觉得学习一门语言不是做了几个项目就可以认为自己会了,这只是暂时的,若没有笔记,时间长了,你是怎么解决某些问题,估计连你自己都忘了,又得费时费 ...
- java 第五章 方法定义及调用
1.方法的定义 什么是方法 方法是完成某个功能的一组语句,通常将常用的功能写成一个方法 方法的定义 [访问控制符] [修饰符] 返回值类型 方法名( (参数类型 形式参数, ,参数类型 形式参数, , ...
- linux-clone-ip处理办法
vim /etc/udev/rules.d/70-persistent-net.rules 步骤1:#将eth0相关的文件给删除 步骤2:#vi /etc/sysconfig/network-scri ...
- RTL8195AM开发板使用
1. 本次使用RTL8195AM测试一下,原厂资源地址:https://os.mbed.com/platforms/Realtek-RTL8195AM/ 2. 由于板子支持mbed,所以把CON2连接 ...
- java线程池技术
1.线程池的实现原理?简介: 多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力.假设一个服务器完成一项任务所需时间为:T1 创建线程时间, ...
- Smart Framework:轻量级 Java Web 框架
Smart Framework:轻量级 Java Web 框架 收藏 黄勇 工作闲暇之余,我开发了一款轻量级 Java Web 框架 —— Smart Framework. 开发该框架是为了: 加 ...
- 大数据de 2文章
点击可免费试用网易有数 文章来源:网易有数的搭积木原则阐述 ,经作者文雯授权发布 wo ceceshi 相关文章:[推荐] SpringBoot入门(五)--自定义配置
- Qt QLabel 播放GIF动画
很久以前用过,不过慢慢的不用了,就慢慢的忘记了,今天拾起来,记录一下,以后用的时候可以翻一下 QLabel播放GIF动画其实很简单 第一步,需要包含头文件,Qt播放GIF动画,我使用的是QMovie类 ...