How to analyze the execution time of a SQL statement in MySQL

In different modules, what are the resources (time) used for SQL execution.
How to analyze the execution time of a SQL statement in MySQL
1. First, you need to see whether profiling is turned on. Turning it on allows MySQL to collect the resources used during SQL execution.

select @@profiling;
Insert picture description here

profiling=0 means off, profiling needs to be set to 1

set profiling=1;
Insert picture description here

2. Then execute a SQL query

select * from nodeinfo; 

3. View all profiles generated by the current session:

 show profiles
Insert picture description here

If you want to get the execution time of the last query, you can use

show profile;

Of course, you can also query the executed Query ID, such as

show profile for query 1;
Insert picture description here

After version 8.0 (you can use select version() to check the version of MySQL), MySQL no longer supports cached queries. Once the data table is updated, the cache will be emptied, so only the data table is static or there are few data tables When changes occur, the use of cached queries is valuable.