Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

explain command in mysql

I am quite new to mysql, I came across a keyword called explain tody, can anyone help me explaining what is explain keywords in mysql? and how it is used? in what case?

if anyone could show me examples will be even better, any help will be greatly appreciated!

suppose I have the following mysql table:

create table user
 (
   id unsigned int auto_increment primary key,
   user varchar(15) not null
 )
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Basically explain is used to give you information regarding how the database goes about getting data using a query you specified. Typically you would use it if you have a slow query that you want to analyze.

As far as I know, explains really only apply to statements that are doing data retrieval. So, assuming the table in your create statement exists, a better example would be...

explain select * from user where user='steve'

What you'll get back from this is a table containing some information on how the data was retrieved, not the data itself. In the real world you would probably only use explains with much more complicated queries.

You should try Googling "mysql explain", it turns up some pretty good results that explain the data you will get back when you run an explain query. For example, the information here seems pretty good.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...