Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Check how mysql index is used

   1  
   2  EXPLAIN SELECT ... WHERE ...

Explain will tell you if your index work as you thought.

(I forgot to login in the last two snippets)

Fulltext search in mysql

   1  
   2  mysql> CREATE TABLE articles (
   3      ->   id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
   4      ->   title VARCHAR(200),
   5      ->   body TEXT,
   6      ->   FULLTEXT (title,body)
   7      -> );
   8  Query OK, 0 rows affected (0.00 sec)
   9  
  10  mysql> INSERT INTO articles (title,body) VALUES
  11      -> ('MySQL Tutorial','DBMS stands for DataBase ...'),
  12      -> ('How To Use MySQL Well','After you went through a ...'),
  13      -> ('Optimizing MySQL','In this tutorial we will show ...'),
  14      -> ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
  15      -> ('MySQL vs. YourSQL','In the following database comparison ...'),
  16      -> ('MySQL Security','When configured properly, MySQL ...');
  17  Query OK, 6 rows affected (0.00 sec)
  18  Records: 6  Duplicates: 0  Warnings: 0
  19  
  20  mysql> SELECT * FROM articles
  21      -> WHERE MATCH (title,body) AGAINST ('database');
  22  +----+-------------------+------------------------------------------+
  23  | id | title             | body                                     |
  24  +----+-------------------+------------------------------------------+
  25  |  5 | MySQL vs. YourSQL | In the following database comparison ... |
  26  |  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |
  27  +----+-------------------+------------------------------------------+
  28  2 rows in set (0.00 sec)


More information here.
http://dev.mysql.com/doc/mysql/en/fulltext-search.html
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS