免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 红豆抹茶
打印 上一主题 下一主题

【ChinaUnix社区站庆图书专题】MySQL之InnoDB存储引擎(获奖名单已公布2012-11-30) [复制链接]

论坛徽章:
11
CU十二周年纪念徽章
日期:2013-10-24 15:41:342015年辞旧岁徽章
日期:2015-03-03 16:54:15丑牛
日期:2015-01-14 10:36:40技术图书徽章
日期:2015-01-12 15:46:11白羊座
日期:2014-11-14 09:35:36狮子座
日期:2014-10-30 13:18:49巳蛇
日期:2014-10-11 12:52:08子鼠
日期:2014-09-28 14:11:06双鱼座
日期:2014-04-22 13:05:48午马
日期:2014-02-11 17:58:002015年迎新春徽章
日期:2015-03-04 09:55:28
21 [报告]
发表于 2012-11-23 12:06 |只看该作者
没使用过,来支持一下!

论坛徽章:
10
CU大牛徽章
日期:2013-05-20 10:44:54数据库技术版块每日发帖之星
日期:2015-06-09 22:20:00IT运维版块每日发帖之星
日期:2015-06-05 22:20:00亥猪
日期:2014-08-23 14:52:27摩羯座
日期:2013-11-29 18:02:31CU十二周年纪念徽章
日期:2013-10-24 15:41:34CU大牛徽章
日期:2013-05-20 10:45:31CU大牛徽章
日期:2013-05-20 10:45:24CU大牛徽章
日期:2013-05-20 10:45:13综合交流区版块每日发帖之星
日期:2016-02-12 06:20:00
22 [报告]
发表于 2012-11-23 14:11 |只看该作者
InnoDB是mysql数据库的一种存储引擎。此外还有好几种存储引擎如MyISAM,MERGE, MEMORY, BerkeleyDB, CSV, ARCHIVE。对于业务使用哪种引擎需要看具体的业务,也不是说innodB就一定好~

论坛徽章:
0
23 [报告]
发表于 2012-11-26 16:46 |只看该作者
我也是来学习的.作为一个开发者,对数据库确实需要多了解些.
不过我知道的也就只是:InnoDB支持事务;MyISAM不支持.
4楼和7楼,让我学习了.!!
这样的讨论贴多些好.

论坛徽章:
0
24 [报告]
发表于 2012-11-26 16:48 |只看该作者
楼下的saysaysee
说说看.

论坛徽章:
0
25 [报告]
发表于 2012-11-26 20:07 |只看该作者
回复 1# 红豆抹茶


    1、InnoDB存储引擎和其他常用引擎有什么区别,您更偏爱哪一种,原因是什么?
2、简述InnoDB存储引擎有哪些优点和缺点?
3、在使用InnoDB存储引擎的过程中你所遇到的困难和解决的方法。

个人理解如下:
1 innodb比MYISAM快
2 性能并不足以让你修改自己表的engine
3在空间分配上,innodb的空间是myisam的2x-3x
4当表的engine从myisam convert to innodb的时候,要注意的索引的不同 ,尤其是PK,innodb要求每一个表都有一个PK,myisam的第一unique
Key  就作为第一个PK
5 在shou  table  status的时候,显示信息rows,avg_row_length可能会有offset,offset是2的倍数(这个偶还在测试中)
6 尽量多使用innodb而不是myisam
7 不要让 Begin  。。。commit的执行时间超过5秒钟
8 使用begin,而不是 autocommit=0,该值不建议使用,default value  =1
9 针对mysiam,不必使用optimize table ,除非show table status 显示可以节省10%以上的空间
针对innodb,不必使用optimize table
10  engine使用bufferpool也不同,
myisam 的索引缓存在key_buffer_size,而数据使用OS缓存,
innodb 的bufferpool使用innodb_buffer_size
至于engine的偏好,因热而异吧~~~~~~~~
至于遇到的问题,比较典型的一个是drupal ---汉化包上传超时处理方法,请参考(http://blog.chinaunix.net/uid-22334392-id-3346990.html
解决的方法是修改 innodb_flush_log_at_trx_commit
它描述的是innodb flush  log的频率,具有好几个不同的值,如果该值设置不当,innodb的效率可能比较低,
0表示 在事务提交的时候不一定写log ,写log的频率是1秒钟然后将log写到log file 然后flush到磁盘
1表示每次事务提交的时候,都将logbuffer写到log file同时将log file flush到磁盘
2表示每次事务提交的时候,都将log buffer写到log file,但是什么时候flush 到磁盘则有OS 来决定,OS flush的频率仍是1秒(该值为平均值,具体的情况要看OS的负载)
具体选择何值,与你的应用息息相关。
具体的解释如下
innodb_flush_log_at_trx_commit

Command-Line Format        --innodb_flush_log_at_trx_commit[=#]
Option-File Format        innodb_flush_log_at_trx_commit
Option Sets Variable        Yes, innodb_flush_log_at_trx_commit
Variable Name        innodb_flush_log_at_trx_commit
Variable Scope        Global
Dynamic Variable        Yes
        Permitted Values
Type        enumeration
Default        1
Valid Values       
0

1

2

If the value of innodb_flush_log_at_trx_commit is 0, the log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but nothing is done at a transaction commit. When the value is 1 (the default), the log buffer is written out to the log file at each transaction commit and the flush to disk operation is performed on the log file. When the value is 2, the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. However, the flushing on the log file takes place once per second also when the value is 2. Note that the once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues.

The default value of 1 is the value required for ACID compliance. You can achieve better performance by setting the value different from 1, but then you can lose at most one second worth of transactions in a crash. With a value of 0, any mysqld process crash can erase the last second of transactions. With a value of 2, then only an operating system crash or a power outage can erase the last second of transactions. However, InnoDB's crash recovery is not affected and thus crash recovery does work regardless of the value.

For the greatest possible durability and consistency in a replication setup using InnoDB with transactions, use innodb_flush_log_at_trx_commit = 1 and sync_binlog = 1 in your master server my.cnf file.

Caution
Many operating systems and some disk hardware fool the flush-to-disk operation. They may tell mysqld that the flush has taken place, even though it has not. Then the durability of transactions is not guaranteed even with the setting 1, and in the worst case a power outage can even corrupt the InnoDB database. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try using the Unix command hdparm to disable the caching of disk writes in hardware caches, or use some other command specific to the hardware vendor.
参考文档地址:
http://docs.oracle.com/cd/E17952 ... h_log_at_trx_commit

论坛徽章:
0
26 [报告]
发表于 2012-11-27 04:44 |只看该作者
MyISAM 备份迁移方便,修复方便。
innodb突然断电容易损坏表,难修复

论坛徽章:
2
CU大牛徽章
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
27 [报告]
发表于 2012-11-27 12:06 |只看该作者
我的几十个业务已经90%使用Innodb,10%的基本上只读不写的库还在用MyISAM。
有人说innodb已经全面超越了MyISAM,新版的mysql5.6会使用Innodb作为默认引擎。

Innodb比较坑爹的地方是select count(*)  where field="xx";  ,表大了卡得一塌糊涂。不知道官方为什么不做更多优化。
行级锁其实很多人有点误解,Innodb并不是严格行级锁,他是间隙锁。比如update xxx set click=click+1 where id=5 and id=100.他是会把5-100间的所有行锁住,而不是只锁两行。
当然只对主键进行操作是相当于是行级锁了,如update ... where id=100这种情况

外键依赖虽然符合第三范式,不知道有谁,什么业务在用,反正我是从来不用。哪位用过或觉得他适用的请指点一二。



论坛徽章:
3
射手座
日期:2013-10-12 12:01:59技术图书徽章
日期:2014-03-06 15:32:30技术图书徽章
日期:2014-03-06 15:42:47
28 [报告]
发表于 2012-11-27 15:24 |只看该作者
统计行数可以用 select max(id) from table   这个不会扫描全表吧?id 如你说的第三条,auto_increment 字段,可以作为查询依据。如果没必要是不会加这个id 的对吧? 呵呵请多多指教! 谢谢回复 12# crazyhadoop


   

论坛徽章:
0
29 [报告]
发表于 2012-11-28 09:34 |只看该作者
公司的所有数据库都是MySQL,而已正好也全部都用InnoDB引擎。
还在学习中,看评论取经验。不评论……

论坛徽章:
2
辰龙
日期:2013-09-24 12:26:05卯兔
日期:2013-09-24 12:27:37
30 [报告]
发表于 2012-11-28 18:13 |只看该作者
我键盘坏了 楼主把握上面的帖给删掉吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP