The data in a MYSQL table has reached 20 million entries. how can I further optimize the data in a MYSQL table? it has reached 20 million data records, and the query is very slow. I don't know how to improve it? The current method is to do a lot of cache tables, but the data is not real-time. It takes 7 seconds for me to execute such a statement selectmax (id) fromunit_keywords. the machine performance is good, 64-bit, 4-core, 8 GB memory ----- how can I further optimize a MYSQL table with 20 million data entries?
One MYSQL table contains 20 million data records.
Data Query is slow and slow. I don't know how to improve it?
The current method is to do a lot of cache tables, but the data is not real-time.
I have executed such a statement select max (id) from unit_keywords for 7 seconds. the machine performance is good, with 64-bit, 4-core, and 8 GB memory.
------ Solution --------------------
Check whether the primary key and index are correctly constructed.
Is text used as the primary key?
Even if it is more than 20 million, it will not take 7 seconds.
------ Solution --------------------
Check the mysql configuration file.
Maybe your configuration is for small databases.
------ Solution --------------------
W. The performance is still so high. let's look at the mysql buffer settings.
If not, just split the table.
------ Solution --------------------
In fact, this problem should not be released in the PHP version. In fact, you should ask the DBA and system architect to help you solve the problem.
From the perspective that the select max (id) from table requires 7 s, it is also possible to consider id as the primary key for auto-growth, this means that your business has suffered lock competition. (If this field is not a primary key or index, your machine configuration is quite good if the return value is 7 s under 20 million rows)
I think your business may have the SELECT, INSERT, and UPDATE operations on the table at the same time, or even DELETE operations. In fact, many businesses use MySql MyISAM tables to pursue performance, and optimize their businesses with only SELECT and INSERT operations. This is because INSERT does not need to lock the table, and SELECT does not lock each other. To UPDATE data, you can strip the fields to be updated to the new table and UPDATE the new table (of course, this makes no sense if the UPDATE operation is too frequent ).
In addition, the index is created based on the query clause of the service. The Explain command of MySql can be used as a reference.
We recommend that you use another cache service, such as APC or Memcache, to update the cache while updating data.
I am not clear about your table structure. I just want to explain some common practices. If you can, we recommend that you release the show create table result for better analysis.