大家都知道mysql的myisam表适合读操作大,写操作少;表级锁表
innodb表正好相反;行级锁表互联网服务,不算支付性的服务外,互动产品,新闻系统等等一般都是读多,写少。用myisam表比较合适。
表的设计
定长表:所有列的字段长度都是定长的。可以去查mysql的手册不定长字段是VARCHAR、BLOB或TEXT。int char都是定长的,定长表占用空间会大。
动态表:就是字段不是都定长的。
定长表要比动态表检索速度快。
软件系统的设计习惯是把每张表都分清很明确的功能,比如用户表都是用户信息,如果需要同时从留言表取数据,又从用户表取用户信息的时候,就会采用联合查 询,有的时候一些操作还会用left,join等各种复杂sql语句,没准还要用mysql的函数。如果是针对访问量,读取量很大的互联网服务时,同时并 发去读,数据量又大,很可怕。最好是如果数据不会修改,在常用的表上有冗余字段,能够做到一次读,把数据都拿到;可以有冗余的写操作,但减少复杂的查询操 作。
在设计表的时候要将这个表的所有字段类型占用的字节数求和,并乘以你的预期(如:存储100W数据量),就是整张表未来会占用容量。
拆表 拆库
拆表就是将一张表复制N多张,里面分别存放不用内容的数据,数据的存放是用HASH算法来决定放入哪张表。
例如用户表user,传统情况就是一张表,拆表就是将表复制为user_01,user_02等里面都存放了格式一样的不同用户数据。
拆库和拆表类似,就是库的复制。
拆表或拆库有很多的HASH算法,主要目的就是减少表的数据量,用算法保证每个表的数据量平均,请求,读写操作被分摊降低压力,而且安全,出了问题最多是一部分用户受影响。缺点就是检索不方便,需要另想办法。
很多网站为了前期省事都会采用discuz的产品,如bbs,blog等,网上有不少关于这个产品的介绍和优化方法,没细研究过,听过一些网站介绍他们的 优化方法时,对于数据库主要是采用主从的方法,将数据库的读写分离来提高性能,但是个人觉得这种办法在数据量到了规模的时候就OVER了,并发和读写操作 没提升,数据也是会逐渐累计超过限制。
互联网服务由于要应对大数据量,大请求量,所以在设计开发的时候就不要太学院派,不要力图达到数据库、程序的设计“优美”,性能是最要紧的。

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment