MySQL storage structure diagram:

Analysis:
1. Read operation: memory read - ->cache cache read-->Disk physical read
The data read will be sent back in the above order.
2. Write operation: memory data is written directly into cache (very fast) --> write to disk
From the above, it can be seen that cache is one of the reasons why MySQL has fast reading and writing speed. played a key role.
1. Cache features:
1. Fast speed
2. Data loss during power failure
3. Limited capacity
2. Protect data security (prevent data loss due to unexpected power outage) Countermeasures:
In storage, add BBU (battery backup unit, which is the battery). After power outage, the data in the cache can be written to the disk to ensure that data will not be lost.
If the BBU is not provided or the BBU is broken, the memory data will not be written to the cache cache, but will be written directly to the disk; compared to writing to the memory, the speed of writing to the disk will be greatly reduced ( ten thousand times difference). At the same time, the slower "writing" takes up most of the "reading" bandwidth. Therefore, the BBU problem is a major influencing factor of poor read and write performance.
3. The cache cache capacity is limited
(4G, 8G, 16G, 32G). In order to keep the cache useful, the system will periodically write the cached data to the disk to avoid cache occupied.
2. Analysis of slow storage writing speed
Database-->Slow writing speed-->System hangs
Q: How to judge the slow writing speed?
A:
1. Suspected BBU problem
Monitor the BBU bug and solve it by restarting the BBU
2. The cache is full (similar to BBU is broken)
1. A large amount of written data fills up the cache cache. Judgment:
shell> iostat -x
mysql> show global status like 'handler_write ';
2. The speed of cache writing to disk is slow (the drainage speed is much slower than the water filling speed)
Hard disk I/O is abnormal and the load is too high: massive physical reads of the database (abnormal SQL ), judgment:
mysql> show status like 'Innodb_buffer_pool_reads';
3. Problem of poor storage performance
1. Poor storage device, update the device
2. Risks of disaster recovery synchronization, "No matter how good the engineer is, he is no match for Lan Xiang's excavator and migrant workers' hoes..."
3. About BBU
English abbreviation: BBU
English full name: Battery Backup Unit
Chinese full name: Battery Backup Unit, which is the battery
1. Function:
After power failure, the cache The data is written to the hard disk to ensure that the data will not be lost;
is a protection measure for brushing dirty data due to accidental power outage;
can provide data protection when the external power supply of the system fails. Backup power supply support to ensure the security of business data in the storage array.
2. Many storage devices will be equipped with BBU
BBU provides power for the RAID controller cache when there is a problem with the power supply. When the power is off, the BBU power can save the data in the cache in the controller for a certain period of time (depending on the BBU model). Users only need to restore normal power supply before the BBU power is exhausted (battery is limited), and the data in the cache can be completely written back to the RAID to avoid data loss caused by power outage.
It is a little different from the server battery. In the server, you can configure a battery when configuring the RAID card. After the system is powered off, the data in the memory can be maintained without losing it, but the time is limited, about 12 hours. About 12 hours, if it is not restored within 12 hours, the data in the memory will be lost;
3. Supercapacitor
The server also has a protection method called supercapacitor, which is also Matched with the RAID card, it can write the data in the cache to the capacitor after the server is powered off, and it will be saved permanently. It is similar to writing to a hard disk, but actually writing to the capacitor. You can understand it as writing to a USB flash drive. . It is better than batteries. Even if the server does not restore power after 12 hours, there will be no data loss.
The above is the detailed content of How is the writing speed of Mysql storage formed?. For more information, please follow other related articles on the PHP Chinese website!

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools
