mysql各种存储引擎(一) mysql各种存储引擎一 MyISAM MyISAM文件格式 MyISAM文件修复 MyISAM表的存储格式 Innodb存储引擎 支持事物 自动增长列 外键约束 存储结构 MyISAM MyISAM文件格式 frm文件 存储表的结构定义数据 MYD文件 具体的数据文件 MYI文件 表索
mysql各种存储引擎(一)
-
-
- mysql各种存储引擎一
- MyISAM
- MyISAM文件格式
- MyISAM文件修复
- MyISAM表的存储格式
- Innodb存储引擎
- 支持事物
- 自动增长列
- 外键约束
- 存储结构
- MyISAM
- mysql各种存储引擎一
-
MyISAM
MyISAM文件格式
- frm文件 存储表的结构定义数据
- MYD文件 具体的数据文件
- MYI文件 表索引文件
myISAM存储引擎只缓存索引,对数据文件采用操作系统缓存,如果索引数据超过系统所分配的缓存空间时也会采用操作系统来缓存索引.
MyISAM文件修复
- 通过使用check table语句检测MyISAM表的状态,然后用REPAIR TABLE语句修复损坏的表
- 使用myisamchk工具修复,如果有用户同时在操作这张表,那么即使表是没有问题的,也很有可能提示表已损坏,故进行检查时,应当先停掉mysql服务。如果不想停止服务,至少应该mysqladmin flush-tables操作。
<code class=" hljs haml"> [? JavaStudy git:(master) myisamchk -e books.MYI Checking MyISAM file: books.MYI Data records: 0 Deleted blocks: 0 -<span class="ruby"> check file-size </span> -<span class="ruby"> check record delete-chain </span> -<span class="ruby"> check key delete-chain </span> -<span class="ruby"> check index reference </span> -<span class="ruby"> check data record references <span class="hljs-symbol">index:</span> <span class="hljs-number">1</span> </span> -<span class="ruby"> check records <span class="hljs-keyword">and</span> index references </span></code>
MyISAM表的存储格式
- 静态(固定长度)表 默认格式,固定非变长字段,存储速度快,容易缓存,易恢复,缺点所占空间较多,且利用率不高
- 动态可变长度表,可变长存储,恢复困难,行变化较大时会被分成碎片,需要使用myisamchk -r 来修复
- 压缩表 存储空间最小,每行进行压缩,使用数据库提供的myisanpack工具压缩。
Innodb存储引擎
支持事物
4个事物级别:
- read uncommitted 最低级别,以下情况均无法保证
- read committed 可避免脏读情况发生
- repeatable read 可避免脏读、不可重复读情况的发生 数据库的默认级别
- serializable 可避免脏读、不可重复读、虚读情况的发生
自动增长列
auto_increment属性,表在添加数据的时候,可以插入空值,该列可以自动增加数据
外键约束
它降低了数据库的查询效率,数据库表之间的耦合度更加紧密,要求父表必须有相对应的索引,字表在创建时回添加相应的索引。
存储结构
- .frm文件 数据的结构定义文件
- .ibd文件 数据与索引文件
(1)使用共享表空间
所有的表盒索引数据存放在同一个表空间中,数据和索引在innodb_data_home_dir和innodb_data_file_path定义的表空间中,可以使用一个或多个数据文件
(2)使用多表空间
表结构存放在.frm文件中,但是每个表的数据和索引文件存放在一个单独的.ibd文件中.要使用多表空间存储时,需要设置innodb_file_per_table参数,这样每个数据库的表都会生成一个数据空间
查看如下:
<code class=" hljs lua"> mysql> show variables like <span class="hljs-string">'%per_table%'</span>; +<span class="hljs-comment">-----------------------+-------+</span> | Variable_name | Value | +<span class="hljs-comment">-----------------------+-------+</span> | innodb_file_per_table | ON | +<span class="hljs-comment">-----------------------+-------+</span> <span class="hljs-number">1</span> row <span class="hljs-keyword">in</span> set (<span class="hljs-number">0.00</span> sec) </code>
修改前需要关闭数据库,然后在配置文件my.cnf中设置或者添加该参数innodb_file_per_table = 1,重启数据库服务。

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.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)