【转】MySql官方建议:Innodb表最佳实践

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
原文:http://dev.mysql.com/doc/refman/5.5/en/innodb-default-se.html
Best Practices for InnoDB Tables
If you have been using InnoDB for a long time, you already know about features like transactions and foreign keys. If not, read about them throughout this chapter. To make a long story short:

1) Specify a primary key for every table using the most frequently queried column or columns, or an auto-increment value if there isn't an obvious primary key.
指定主键:使用最频繁查询的一个或者多个列作为主键,如果没有,就使用自增id作为主键


2) Embrace the idea of joins, where data is pulled from multiple tables based on identical ID values from those tables. For fast join performance, define foreign keys on the join columns, and declare those columns with the same datatype in each table. The foreign keys also propagate deletes or updates to all affected tables, and prevent insertion of data in a child table if the corresponding IDs are not present in the parent table.
拥抱join:当数据从多个表里面按照相同的ID值取出来的时候,优先使用join,可以使用外键来提高join的性能。


3) Turn off autocommit. Committing hundreds of times a second puts a cap on performance (limited by the write speed of your storage device).
关闭autocommit:每秒提交几百次会限制性能。
(译者注:业务系统建议不要关闭,否则编程比较麻烦,批量导入数据的时候可以关闭,然后定时或者定量commit)


4) Bracket sets of related changes, logical units of work, with START TRANSACTION and COMMIT statements. While you don't want to commit too often, you also don't want to issue huge batches of INSERT, UPDATE, or DELETEstatements that run for hours without committing.
使用事务提交,避免频繁提交


5) Stop using LOCK TABLE statements. InnoDB can handle multiple sessions all reading and writing to the same table at once, without sacrificing reliability or high performance. To get exclusive write access to a set of rows, use theSELECT ... FOR UPDATE syntax to lock just the rows you intend to update.
不要使用LOCK TABLE操作,Innodb的机制能够支持高并发操作,且不损失可靠性和性能。推荐使用SELECT....FOR UPDATE


6) Enable the innodb_file_per_table option to put the data and indexes for individual tables into separate files, instead of in a single giant system tablespace. (This setting is required to use some of the other features, such as table compression and fast truncation.)
打开innodb_file_per_table选项

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
Oracle 关系型数据库 MySQL
【mysql】—— 表的内连和外连
【mysql】—— 表的内连和外连
|
1月前
|
存储 关系型数据库 MySQL
【mysql】—— 表的增删改查
【mysql】—— 表的增删改查
|
23天前
|
存储 SQL 关系型数据库
【MySQL】4. 表的操作
【MySQL】4. 表的操作
21 0
|
14天前
|
存储 关系型数据库 MySQL
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
29 0
|
22天前
|
存储 关系型数据库 MySQL
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
MySQL数据库性能大揭秘:表设计优化的高效策略(优化数据类型、增加冗余字段、拆分表以及使用非空约束)
|
22天前
|
缓存 关系型数据库 MySQL
MySQL 查询优化:提速查询效率的13大秘籍(索引设计、查询优化、缓存策略、子查询优化以及定期表分析和优化)(中)
MySQL 查询优化:提速查询效率的13大秘籍(索引设计、查询优化、缓存策略、子查询优化以及定期表分析和优化)(中)
|
23天前
|
关系型数据库 MySQL
【MySQL】12. 表的内连和外连(重点)
【MySQL】12. 表的内连和外连(重点)
13 0
|
29天前
|
缓存 关系型数据库 MySQL
为啥MySQL官方不推荐使用uuid或者雪花id作为主键
为啥MySQL官方不推荐使用uuid或者雪花id作为主键
23 1
|
1月前
|
存储 关系型数据库 MySQL
【mysql】—— 表的约束
【mysql】—— 表的约束
|
1月前
|
存储 SQL 关系型数据库
【mysql】—— 表的操作
【mysql】—— 表的操作