


Detailed introduction to ten parameters for optimizing mysql performance
(1), back_log:
The required number of connections that MySQL can have. This works when the main MySQL thread gets a lot of connection requests in a short period of time, and then the main thread takes some time (albeit briefly) to check for connections and start a new thread. The
back_log value indicates how many requests can be stored in the stack in a short period of time before MySQL temporarily stops answering new requests. Only if you expect many connections in a short period of time you need to increase it, in other words, this value is the size of the listening queue for incoming TCP/IP connections. Your operating system has its own limit on this queue size. Attempting to set back_log higher than your operating system's limit will have no effect.
When you observe your host process list and find a large number of 264084 | unauthenticated user | xxx.xxx.xxx.xxx | NULL | Connect | NULL | login | NULL processes to be connected, you need to increase the value of back_log. The default value is 50, I changed it to 500.
(2), interactive_timeout:
The number of seconds the server waits for action on an interactive connection before closing it. An interactive client is defined as one that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). The default value is 28800, I changed it to 7200.
(3), key_buffer_size:
The index block is buffered and shared by all threads. key_buffer_size is the buffer size used for index blocks, increase it to get better handling of the index (for all reads and multiple writes), to as much as you can afford. If you make it too big, the system will start paging and really slow down. The default value is 8388600 (8M), my MySQL host has 2GB of memory, so I changed it to 402649088 (400MB).
(4), max_connections:
The number of simultaneous clients allowed. Increasing this value increases the number of file descriptors required by mysqld. This number should be increased, otherwise, you will see Too many connections errors frequently. The default value is 100, I changed it to 1024.
(5), record_buffer:
Each thread that performs a sequential scan allocates a buffer of this size for each table it scans. If you do a lot of sequential scans, you may want to increase this value. The default value is 131072 (128K), I changed it to 16773120 (16M)
(6), sort_buffer:
Each thread that needs to be sorted allocates a buffer of this size. Increasing this value speeds up ORDER BY or GROUP BY operations. The default value is 2097144 (2M), I changed it to 16777208 (16M).
(7), table_cache:
The number of open tables for all threads. Increasing this value increases the number of file descriptors required by mysqld. MySQL requires 2 file descriptors for each unique open table. The default value is 64, I changed it to 512.
(8), thread_cache_size:
The number of threads saved in that can be reused. If there is, the new thread is fetched from the cache, and if there is space when the connection is disconnected, the client's thread is placed in the cache. If there are many new threads, this variable value can be used to improve performance. You can see the role of this variable by comparing the variables in the Connections and Threads_created states. I set it to 80.
(9) Mysql search function
Use mysql to search, the purpose is to be case-insensitive and search in Chinese
Just specify --default-character-set=gb2312 when starting mysqld
(10) , wait_timeout:
The number of seconds the server waits for action on a connection before closing it. The default value is 28800, I changed it to 7200.
Note: Parameter adjustment can be achieved by modifying the /etc/my.cnf file and restarting MySQL. This is a relatively cautious job, and the above results are just my opinions. You can further modify it according to the hardware conditions of your own host (especially the memory size).
Thank you very much for reading! If you want to get more related articles, please pay attention to the PHP Chinese website (www.php.cn)!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

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.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
