MySQL can use the profiling command to see how long it takes to execute query SQL.
By default, MySQL is turned off by the profiling command:
[SQL]View PlainCopy
- SELECT @ @profiling;
+-------------------+
| @ @profiling |
+-------------------+
| 0 |
+-------------------+
Description
0: Indicates that the profiling function is off;
1: Indicates open.
The profiling function can be turned on/off by command.
Open command:
[SQL]View PlainCopy
- Set profiling=1;
Close command:
[SQL]View PlainCopy
- Set profiling=0;
such as query command:
SELECT * FROM Employee limit 1, 10;
You can use the profiling command to see how long it takes to execute this sql:
[SQL]View PlainCopy
- Show Profiles;
Query Result:
+----------------+-----------------+-------------------------------------------------------------+
| query_id | Duration | Query |
+----------------+-----------------+--------------------------------------------------------------+
| 1 | 0.00083225 | SELECT * FROM Employee limit 1,10 |
+----------------+-----------------+--------------------------------------------------------------+
1 row in Set (0.00 sec)
Use explain to analyze whether a hit index
[SQL]View PlainCopy
- mysql> explain select * from user where username = ' a ';
- +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+
- | ID | Select_type | Table | type | possible_keys | Key | key_len | ref | Rows | Extra |
- +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+
- | 1 | Simple | user | ref | user_index | user_index | 1 | Using where |
- +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+
- 1 row in Set (0.00 sec)
You can see that you have hit index User_index
Explain and profiling parsing query SQL time