Table of Contents
1. Basic configuration
innodb_buffer_pool_size:
innodb_log_file_size:
max_connections:
2. InnoDB configuration
innodb_file_per_table:
innodb_flush_log_at_trx_commit:
innodb_flush_method:
innodb_log_buffer_size:
3. Other settings
query_cache_size:
log_bin:
skip_name_resolve:
Summary
Home Database Mysql Tutorial MySQL - A detailed introduction to the 10 configurations that must be adjusted for the newly installed MySQL

MySQL - A detailed introduction to the 10 configurations that must be adjusted for the newly installed MySQL

Mar 09, 2017 pm 01:12 PM

Are you still worried about the newly installed mysql service and don’t know which default configurations to modify? There are more than 100 adjustable parameters of mysql. Which of the most important parameters should be adjusted immediately! Immediately!

This article mainly introduces 10 configurations that must be adjusted for MySQL optimization. Using these methods can allow you to quickly obtain a robust MySQL configuration. Friends in need can refer to the following:

When we are being When hired to monitor MySQL performance, people expect us to review the MySQL configuration and make suggestions for improvements. Many people are surprised when we suggest they change only a few settings, even though there are hundreds of configuration options. The purpose of this article is to give you a very important list of configuration items.

We gave this advice on the blog a few years ago, but the world of MySQL is changing so fast!

Written before we start...

Even though Even experienced people can make mistakes, which can cause a lot of trouble. So before blindly applying these recommendations, please remember the following:

Change only one setting at a time! This is the only way to test whether the changes are beneficial.

Most configurations can be changed at runtime using SET GLOBAL. This is a very convenient way to quickly undo changes if something goes wrong. However, to make it permanent you need to make changes in the configuration file.

A change does not work even if Mysql is restarted?

Please make sure you use the correct configuration file. Please make sure you place the configuration in the correct area (all configurations mentioned in this article belong to [mysqld])

The server cannot start after changing a configuration: Please make sure you use the correct configuration The unit.

For example, the unit of innodb_buffer_pool_size is MB and max_connection has no unit.

Do not have duplicate configuration items in a configuration file. If you want to track changes, use version control.

Don't use naive calculation methods, such as "Now my server has twice the memory of before, so I have to change all values ​​​​to double the previous value."

1. Basic configuration

You need to check the following three configuration items frequently. Otherwise, problems may arise quickly.

innodb_buffer_pool_size:

This is the first option you should set after installing InnoDB.

The buffer pool is where data and indexes are cached: the larger the value, the better. This ensures that you use memory instead of the hard disk for most read operations. Typical values ​​are 5-6GB (8GB memory), 20-25GB (32GB memory), 100-120GB (128GB memory).

innodb_log_file_size:

This is the size of the redo log. Redo logging is used to ensure write operations are fast and reliable and to recover from crashes.

Up until MySQL 5.1, it was difficult to tune because on the one hand you wanted it to be bigger to improve performance, and on the other hand you wanted to make it smaller to recover faster after a crash. Fortunately, since MySQL 5.5, the crash recovery performance has been greatly improved, so that you can have high write performance and crash recovery performance at the same time. Until MySQL 5.5, the total size of the redo log was limited to 4GB (there can be 2 log files by default). This has been improved in MySQL 5.6.

Set innodb_log_file_size to 512M from the beginning (so there is a 1GB redo log), which will give you ample space for write operations. If you know that your application needs to write data frequently and you are using MySQL 5.6, you can set it to 4G from the beginning.

max_connections:

If you often see the 'Too many connections' error, it is because the value of max_connections is too low. This is very common because the application does not close database connections properly and you need a higher value than the default 151 connections. A major drawback when the max_connection value is set high (such as 1000 or higher) is that the server becomes unresponsive when running 1000 or higher active transactions. Using connection pooling in your application or process pooling in MySQL can help solve this problem.

2. InnoDB configuration

Starting from MySQL version 5.5, InnoDB is the default storage engine and it is used much more than any other storage engine. That's why it needs to be configured carefully.

innodb_file_per_table:

This setting tells InnoDB whether it needs to store data and indexes for all tables in a shared table space (innodb_file_per_table = OFF) or for each table The data is placed in a separate .ibd file (innodb_file_per_table = ON). One file per table allows you to reclaim disk space when dropping, truncating, or rebuilding tables. This is also necessary for some advanced features, such as data compression. But it doesn't bring any performance gain. The main scenario where you don't want one file per table is if you have a very large number of tables (e.g. 10k+).

In MySQL 5.6, the default value of this property is ON, so in most cases you don't need to do anything. With previous versions you had to set this property to ON before loading data, as it only affected newly created tables.

innodb_flush_log_at_trx_commit:

The default value is 1, indicating that InnoDB fully supports ACID features. This value is most appropriate when your main concern is data security, such as on a master node. But for systems with slow disk (read and write) speeds, it will bring a huge overhead, because each time flushing changes to the redo log requires additional fsyncs. Setting its value to 2 will result in less reliable (reliable) because the submitted transaction is only flushed to the redo log once per second, but it is acceptable for some scenarios, such as the backup node of the primary node. This value is acceptable. of. A value of 0 is faster, but may result in some data loss in the event of a system crash: only applies to backup nodes.

innodb_flush_method:

This configuration determines how data and logs are written to the hard disk. Generally speaking, if you have a hardware RAID controller and its independent cache uses a write-back mechanism and has battery power failure protection, it should be configured as O_DIRECT; otherwise, in most cases it should be set to fdatasync (default value). sysbench is a great tool to help you decide this option.

innodb_log_buffer_size:

This configuration determines the cache allocated for transactions that have not yet been executed. The default value (1MB) is generally sufficient, but if your transaction contains large binary objects or large text fields, this cache will quickly fill up and trigger additional I/O operations. Look at the Innodb_log_waits status variable, if it is not 0, increase innodb_log_buffer_size.

3. Other settings

query_cache_size:

query cache (query cache) is a well-known bottleneck, even in This is also true when there is not much concurrency.

The best option is to disable it from the beginning, set query_cache_size = 0 (now the default in MySQL 5.6) and use other methods to speed up queries: optimize indexes, add copies to spread the load, or enable additional cache (such as memcache or redis). If you have enabled query cache for your application and haven't noticed any problems, query cache may be useful to you. This is something to be careful of if you want to disable it.

log_bin:

If you want the database server to act as a backup node for the master node, then enabling the binary log is necessary. If you do this, don't forget to set server_id to a unique value. Even with just one server, this (turning on binary logging) is useful if you want to do point-in-time data recovery: restore from your most recent backup (full backup) and apply the changes in the binary log (incremental backup ). Once created, the binary log is saved permanently. So if you don't want to run out of disk space, you can use PURGE BINARY LOGS to purge old files, or set expire_logs_days to specify how many days after which the logs will be automatically purged.

Logging binary logs is not without overhead, so it is recommended to turn this option off if you do not need it on a replica node that is not the primary node.

skip_name_resolve:

When the client connects to the database server, the server performs host name resolution, and when DNS is slow, establishing a connection will also be slow. It is therefore recommended to turn off the skip_name_resolve option when starting the server without doing a DNS lookup. The only limitation is that only IP addresses can be used in GRANT statements later, so care must be taken when adding this setting to an existing system.

Summary

Of course there are other settings that may work, depending on your load or hardware: slow memory and fast disk, high concurrency and write-intensive Under load, you will need special adjustments. However, the goal here is that you can quickly get a robust MySQL configuration without spending too much time adjusting some insignificant MySQL settings or reading the documentation to find out which settings are important to you.


The above is the detailed content of MySQL - A detailed introduction to the 10 configurations that must be adjusted for the newly installed MySQL. For more information, please follow other related articles on the PHP Chinese website!

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

See all articles