Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...