


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!

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

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


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
