post Category: Uncategorized post Comments (0) postApril 11, 2010

How to page in MySql

  • MySql uses the LIMIT keyword
  • Syntax:  LIMIT <first item>, <numberofrows>
  • The first item is 0, not 1.
  • EX:  SELECT * FROM user ORDER BY name WHERE name LIKE ‘j%’ LIMIT 10, 5
  • Example returns the “third” page of a set paged as 5 items per page.

How to List Indexes in MySql

Tired of performance woes with MySql?  Before deciding that normalization is bad, try indexing your MySql tables.

  • SHOW INDEX FROM mydb.mytable
  • SHOW INDEX FROM mytable FROM mydb
  • Statements are equivalent
  • EX:  SHOW INDEX FROM sitedb.user

How to create an index in MySql

  • CREATE INDEX indexname ON tablename(fieldname)
  • EX:  CREATE INDEX idx_user_id ON user(id)

How to create multiple column index (composite index) in MySql

  • CREATE INDEX indexname ON tablename(fieldname1, fieldname2)
  • EX:  CREATE INDEX idx_user_id ON user(id, name)

Sorry, no comments yet.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
If you have a web site or blog, you can type the URL right here. 
This is where you type your comments. 
Remember my information for the next time I visit.