-3

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
 )
heisenberg
  • 9,665
  • 1
  • 30
  • 38
smith
  • 5,341
  • 8
  • 31
  • 38
  • 3
    You obviously didn't even Google this - this is the very first result: http://dev.mysql.com/doc/refman/5.0/en/explain.html. Now if you had questions about what THAT page means, provide specific questions/examples. – josh.trow Feb 07 '12 at 20:38

1 Answers1

1

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.

Carter
  • 2,850
  • 9
  • 44
  • 57