Recently, it was found that the cpu usage of a database has been compared. More than 200%. First, check the slow log of the database and set the slow log to 5 seconds. basically, no daily log is generated and no more than 5 seconds are generated. Showprocesslist; it takes 1-2 seconds to query several select tables. explainselec recently found that the cpu usage of a database has been compared. More than 200%.
First, check the slow log of the database and set the slow log to 5 seconds. basically, no daily log is generated and no more than 5 seconds are generated.
Show processlist;
It takes 1-2 seconds to query several select tables,
Explain select * from xxx, found that no index, full table scan, the amount of data in the past will soon come out, the current total query data is less than 20 thousand, now the amount of data is large, all other tables are at the level of. Previously, only the indexes of large tables were optimized, so the problem was highlighted. After the index is created, the CPU usage is clearly reduced. as far as I know, the cpu usage of msyql is high, which is related to 80% of the cases where no index is used.
In the next show processlist
Multiple statements are found to be in the Writing to net state.
The analysis is basically a select statement, and the query data is too large. the database returns a network write-back failure,
View show global variables like "global max_allowed_packet" only 1 M
Add cache
Set global max_allowed_packet = 134217728
The problem is solved! The reason is that the number of data returned by multiple select statements exceeds the default value.