search
HomeDatabaseMysql TutorialSummary of configuration techniques for MySQL database optimization technology_MySQL

The examples in this article describe the configuration method of MySQL database optimization technology. Share it with everyone for your reference, the details are as follows:

(1) Reduce database access

For pages that can be made static, make them as static as possible

Staticize the parts of a dynamic page that can be static

Some data can be generated as XML or saved as text files

Use data caching technology such as: MemCached

(2) Optimized detection method

1.User experience detection

2.Mysql status detection

Use the show status command in the Mysql command line to get the current mysql status.

Mainly focus on the following attributes:

key_read_requests (number of index read requests) (affected by key_buffer_size setting)

key_reads (number of index read responses)

Key_blocks_used

Qcache_*

Open_tables (affected by table_cache settings)

Opened_tables

table_locks

3. Third-party tool detection

mysqlreport http://hackmysql.com/mysqlreport

mytop http://jeremy.zawodny.com/mysql/mytop/

System and Mysql Log

System commands: top, sar

Mysql Log: slow_query.log

(3) Hardware optimization

In terms of hardware, the part that is most likely to become the bottleneck of Mysql is the disk, followed by CPU and memory

Disk aspect

Using a faster disk will be of great help to Mysql

Use more hard drives and use Raid to increase the speed of a single disk

For Raid method, it is recommended to use Raid 0+1 or Raid 1+0

CPU

There is no doubt that higher frequency CPUs and more CPUs can give Mysql more performance

High performance

Memory

Higher memory often allows more data in Mysql to be cached in memory,

However, an important factor is the need for correct Mysql configuration

Network card

Use Gigabit network card and Gigabit network

(4)Optimization of operating system

1. Do not use the swap area. If there is insufficient memory, add more memory or configure your system to use less memory

2. Don’t use NFS disk

3. Increase the number of open files on the system and MySQL server

Use ulimit –n 65535

4. Increase the number of processes and threads in the system.

5. Close unnecessary applications, optimize hard disk parameters, and use hdparm to test

(5) Application-level optimization

1. Use multi-server load balancing (multiple reads and writes, use replication technology for data synchronization)

2. Table partition (custom partition, mysql5.1 starts to support its own partition function)

3. Use data caching technology memcached

(6) Optimization of Mysql configuration

1.key_buffer(=512): The amount of memory used by the index buffer

This is very important for MyISAM tables. It is better to set it at 25%-30% of the available memory. By checking the status values ​​​​Key_read_requests and Key_reads,

You can know whether the key_buffer setting is reasonable. The ratio key_reads / key_read_requests should be as low as possible, at least 1:100, 1:1000 is better, otherwise it means that the key_buffer setting is a bit too small

2.innodb_buffer_pool_size(= 512): The amount of memory used by the index buffer

3.table_cache (=1024): Size of data table cache area

Whenever MySQL accesses a table, if there is space in the table buffer, the table is opened and placed in it, allowing faster access to the table contents.

By checking the Open_tables and Opened_tables status values ​​during peak running times, you can decide whether the table_cache value needs to be adjusted.

If you find that the value of open_tables is equal to table_cache, and you find that the opened_tables status value is growing, then you need to increase the table_cache parameter value,

You cannot blindly set the table_cache parameter to a large value. If it is set too high, it may cause insufficient file descriptors, resulting in unstable performance or connection failure.

4.sort_buffer_size (=256): Specify the length of the sorting buffer

The allocated memory corresponding to this parameter is exclusive to each connection! If there are 100 connections, the actual total allocated sort buffer size is 100 × 6 = 600MB.

So, for a server with a memory of about 4GB, it is recommended to set it to 6-8M

5.join_buffer_size: The length of the buffer for associated queries

More than 4G of memory, it is recommended to be greater than 32M. The allocated memory corresponding to this parameter is also exclusive to each connection!

6.max_connections (=1024): Number of threads that can be reused

The number of clients allowed to connect to the MySQL server at the same time can be set by observing and estimating the maximum number of concurrent connections at the peak of the system

7.thread_cache(=*): Number of threads that can be reused

Generally set to the number of CPUs × 2

8.innodb_buffer_pool_size(= 512): innodb table cache pool size

This is very important for Innodb tables. Innodb tables are more sensitive to buffering than MyISAM tables. MyISAM can run under the default key_buffer_size setting,

However, Innodb behaves like a snail under the default innodb_buffer_pool_size setting.

Since Innodb caches both data and indexes, there is no need to leave too much memory to the operating system, so if you only need to use Innodb, you can set it up to 70-80% of the available memory.

Some rules that apply to key_buffer are - If your data volume is not large and will not increase dramatically, then there is no need to set innodb_buffer_pool_size too large.

9.innodb_flush_logs_at_trx_commit(=1): Log flush mode after transaction commit

Are you worried that Innodb is 1000 times slower than MyISAM? It seems that you may have forgotten to modify this parameter. The default value is 1, which means that every updated transaction committed (or every statement outside a transaction) will be flushed to disk,

And this is quite resource intensive, especially without battery backup cache. Many applications, especially those converted from MyISAM, just set its value to 2, which means the logs are not flushed to disk,

And only flush to the operating system cache. The log is still flushed to disk every second, so the cost of 1-2 updates per second is usually not lost. If it is set to 0, it will be much faster, but it is also relatively unsafe,

Some transactions will be lost when the MySQL server crashes. Set to 2 to lose the portion of the transaction flushed to the operating system cache.

Readers who are interested in more MySQL-related content can check out the special topics on this site: "Summary of MySQL Index Operation Skills", "Comprehensive Collection of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Comprehensive Collection of MySQL Stored Procedure Skills", " Summary of MySQL database lock related skills" and "Summary of commonly used MySQL functions"

I hope this article will be helpful to everyone’s MySQL database planning.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

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.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

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.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

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

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

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.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

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

How to use MySQL functions for data processing and calculationHow to use MySQL functions for data processing and calculationApr 29, 2025 pm 04:21 PM

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.

An efficient way to batch insert data in MySQLAn efficient way to batch insert data in MySQLApr 29, 2025 pm 04:18 PM

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.

Steps to add and delete fields to MySQL tablesSteps to add and delete fields to MySQL tablesApr 29, 2025 pm 04:15 PM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment