Home Database Mysql Tutorial Summary of configuration techniques for MySQL database optimization technology_MySQL

Summary of configuration techniques for MySQL database optimization technology_MySQL

Aug 20, 2016 am 08:48 AM
mysql optimization database Configuration

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 of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

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

How to build a SQL database How to build a SQL database Apr 09, 2025 pm 04:24 PM

Building an SQL database involves 10 steps: selecting DBMS; installing DBMS; creating a database; creating a table; inserting data; retrieving data; updating data; deleting data; managing users; backing up the database.

See all articles