Linux DB

mysql help tables 사용해서 공부하기

2008.07.25 02:05

jook 조회 수:23223

1. http://dev.mysql.com/ 페이지에 접속해서 Developer Zone -> Documentation 메뉴로 들어가면, MySQL Help Tables 라는 메뉴에서 자신이 사용하는 버전의 help tables압축 파일을 다운로드 받는다.

2. 다운로드 받은 파일의 압축을 풀면 help tables의 dump 파일인 fill_help_tables-버전.sql 파일이 생기게 된다. 이 파일을 mysql 서버에 업로드 하고, 아래와 같이 mysql db에 sql 파일의 내용을 업데이트 한다.

[root@localhost src]# /usr/local/mysql/bin/mysql mysql < fill_help_tables-5.1.sql

3. 데이터 업데이트를 완료한 후 mysql 서버에 접속하면 mysql db 내에 help_category, help_keyword, help_relation, help_topic 네개의 table이 생성된다.  

[root@localhost /root]# /usr/local/mysql/bin/mysql -u root -p mysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.1.24-rc-log Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)

mysql>

4. 이제 본격적으로 help table을 이용해서 mysql 공부를 시작 할 수 있다.. ^^
help 다음에 쿼리문의 일부분을 입력하면 해당 쿼리의 사용법 등에 대한 설명이 나온다. (예제까지.. ^^)

    ex) help select -> select의 사용법이 출력된다.
          help like -> 쿼리문중 like 구문의 사용법이 출력된다.

mysql> help select
Name: 'SELECT'
Description:
Syntax:
SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr, ...
    [FROM table_references
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name' export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

SELECT is used to retrieve rows selected from one or more tables, and
can include UNION statements and subqueries. See [HELP UNION], and
http://dev.mysql.com/doc/refman/5.1/en/subqueries.html.

The most commonly used clauses of SELECT statements are these:

o Each select_expr indicates a column that you want to retrieve. There
  must be at least one select_expr.

o table_references indicates the table or tables from which to retrieve
  rows. Its syntax is described in [HELP JOIN].

o The WHERE clause, if given, indicates the condition or conditions
  that rows must satisfy to be selected. where_condition is an
  expression that evaluates to true for each row to be selected. The
  statement selects all rows if there is no WHERE clause.

  In the WHERE clause, you can use any of the functions and operators
  that MySQL supports, except for aggregate (summary) functions. See
  [HELP =].

SELECT can also be used to retrieve rows computed without reference to
any table.

URL: http://dev.mysql.com/doc/refman/5.1/en/select.html


mysql> help count
Name: 'COUNT'
Description:
Syntax:
COUNT(expr)

Returns a count of the number of non-NULL values of expr in the rows
retrieved by a SELECT statement. The result is a BIGINT value.

COUNT() returns 0 if there were no matching rows.

URL: http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html

Examples:
mysql> SELECT student.student_name,COUNT(*)
    ->        FROM student,course
    ->        WHERE student.student_id=course.student_id
    ->        GROUP BY student_name;

mysql> help like
Name: 'LIKE'
Description:
Syntax:
expr LIKE pat [ESCAPE 'escape_char']

Pattern matching using SQL simple regular expression comparison.
Returns 1 (TRUE) or 0 (FALSE). If either expr or pat is NULL, the
result is NULL.

The pattern need not be a literal string. For example, it can be
specified as a string expression or table column.

URL: http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html

Examples:
mysql> SELECT 'David!' LIKE 'David_';
        -> 1
mysql> SELECT 'David!' LIKE '%D%v%';
        -> 1

mysql>