MySQL must know, study notes Chapter 30 to improve performance

MySQL has its own hardware recommendations like other DBMSs, and these recommendations should be adhered to for production servers.

Generally, the key production DBMS should run on its own dedicated server.

MySQL uses the default settings pre-configured. After a period of time, you should adjust the memory allocation, buffer size and other settings. You can use SHOW VARIABLES and SHOW STATUS to view the current settings.

MySQL is a multi-user and multi-threaded DBMS. If a task is executed slowly, all requests will be executed slowly. If you encounter a significant performance degradation, you can use SHOW PROCESSLIST to display all active processes and their thread IDs and execution time. KILL can also be used to terminate a specific process (root login required).

Sometimes there are multiple ways to write SELECT statements. You should experiment with joins, unions, subqueries, etc. to find the best solution.

Using the EXPLAIN statement allows MySQL to explain how it will execute a SELECT statement.

Generally, stored procedures execute faster than executing the statements one by one.

The correct data type should always be used.

Do not retrieve more data than required. For example, do not use SELECT * unless you need data for each column.

Some operations, such as INSERT, support the optional DELAYED keyword. If you use it, control will be returned to the calling program before the row is inserted. The inserted data will only enter the insert data queue. At this time, the read request will be viewed first, and only when there is no read request. The insert operation is actually performed. Before the data is actually inserted, the read request cannot read the data. If the MySQL process is terminated before the data is actually inserted, the data is not written into the database.

When importing data, you should turn off automatic submission, and it is best to delete indexes (including FULLTEXT) indexes and rebuild them after the import is complete.

Add indexes to improve data retrieval performance. You can view the repeated WHERE clauses and ORDER BY clauses in the SELECT statement. Run these statements to find out which takes a long time. The columns used by this statement need to be indexed.

If there are a series of OR conditions in the SELECT statement, multiple SELECT statements can be used to UNION the final result, and the performance will be greatly improved.

Indexes will improve data retrieval performance, but will reduce the performance of additions, deletions and changes.

LIKE is very slow, it is better to use FULLTEXT instead of LIKE.

A well-optimized table may decrease performance as data is added, deleted, and modified, and the ideal configuration of the table will also change.

Guess you like

Origin blog.csdn.net/tus00000/article/details/111879242