Independent Digital

Creating and managing dynamic websites using Php, MySql, HTML and Wordpress with a bit of PEAR on the side

Entries Comments



Email This Post    Print This Post   

The MySQL manual made easy to read and understand

5 June, 2007 (13:40) | MySQL | By: clive


It can, at a first glance, be difficult to understand the MySQL syntax, especially for those new to programming. Here is a brief summary of the conventions used in the MySQL manual. Use it when you first refer to the MySQL manual. It should help make interpreting the syntax easier.

Text in this style is used for

  • SQL statements
  • database, table, and column names
  • program listings and source code
  • environment variables
    • Example: ?To reload the grant tables, use the FLUSH PRIVILEGES statement.?

Text in this style

  • indicates the names of executable programs and scripts
    • examples being mysql and mysqld

Text in this style is used for

  • variable input for which you should substitute a value of your own choosing.
    • Example: ALTER {DATABASE | SCHEMA} [db_name] alter_specification [alter_specification] ...
      • here you can optionally include the db_name but have to include at least one alter_specification
      • you have to include either DATABASE or SCHEMA (schema is synonymous with database)

Filenames and directory names are written like this:

  • ?The global my.cnf file is located in the /etc directory.?

To specify a wildcard, use the ?%? character.?

Text in this style is used for emphasis

Text in this style is used in

  • table headings
  • and to convey especially strong emphasis.

shell>

  • indicates a command that you execute from your login shell
    • Example: shell> type a shell command here

mysql>

  • indicates a statement that you execute from the mysql client program
    • Example: mysql> type a mysql statement here

The ?shell? is your command interpreter.

  • On Unix, this is typically a program such as sh, csh, or bash.
  • On Windows, the equivalent program is command.com or cmd.exe, typically run in a console window.

When you enter a command or statement shown in an example, do not type the prompt (mysql> or shell>) shown in the example.

Database, table, and column names must often be substituted into statements.

  • the manual uses db_name, tbl_name, and col_name.
    • Example: mysql> SELECT col_name FROM db_name.tbl_name;
      • Here you need to supply your own column name, database name and table name


SQL keywords are not case sensitive and may be written in any lettercase. The manual uses UPPERCASE.

Square brackets (?[? and ?]?) indicate optional words or clauses.

  • Example DROP TABLE [IF EXISTS] tbl_name
    • IF EXISTS is optional and the statement is also valid if written like this:
      • DROP TABLE tbl_name

When a syntax element consists of a number of alternatives, the alternatives are separated by vertical bars (?|?).

  • If the choice is optional then the alternatives are listed within square brackets (?[? and ?]?):
    • Example: TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
      • Here this statement could be written like this, ommiting all the optional alternatives:
        • TRIM (str)
  • If a choice must be made, the alternatives are listed within braces (?{? and ?}?):
    • Example: {DESCRIBE | DESC} tbl_name [col_name | wild]
      • Here a choice must be made, so either of these statements is valid:
        • DESCRIBE tbl_name
        • DESC tbl_name
          • you can include either col_name or wild as these are optional

An ellipsis (...) indicates the omission of a section of a statement

  • to provide a shorter version of more complex syntax.
    • Example, INSERT SELECT is shorthand for the form of INSERT statement that is followed by a SELECT statement.
  • also to indicate that the preceding syntax element of a statement may be repeated.
    • Example, multiple reset_option values may be given, with each of those after the first preceded by commas:
      • RESET reset_option [,reset_option]
        • here it is optional to repeat the reset_option after the ellipsis

Sorry, there are no related posts but check these out