
Shell>mysql [-h host_name] [-u uer_name] [-p your_password]
The initial root password is empty.
|
Privigele |
Column |
Context |
Description |
|---|---|---|---|
|
select |
select_priv |
Tables |
Allow you to perform operations on rows in existing tables in a database.
|
|
insert |
insert_priv |
||
|
update |
update_priv |
||
|
delete |
delete_priv |
||
|
index |
index_priv |
||
|
Allow to create or remove indexes. |
|||
|
alter |
alter_priv |
||
|
Allows to use ALTER TABLE |
|||
|
create |
create_priv |
Databases, tables or indexes |
Allows to create new databases and tables |
|
drop |
drop_priv |
Databases or tables |
Allows to drop databases and tables |
|
grant |
grant_priv |
Alow you to give to other users those privileges you yourself possess. |
|
|
reference |
reference_priv |
|
|
|
reload |
reload_priv |
Server administration |
Are used for administrative operations. |
|
shutdown |
shutdown_priv |
||
|
process |
process _priv |
||
|
file |
file_priv |
File access on server |
Gives you permission to read and write files on the server using the LOAD INFILE and SELECT ... INTO OUTFILE. |
|
Administrative commands that each administrative privilege allows you to execute |
|
|---|---|
|
Privilege |
Commands permitted to privilege holders |
|
reload |
reload, refresh, flush-privileges, flush-hosts, flush-logs, flush-tables |
|
shutdown |
shutdown |
|
Process |
processlist, kill |
MySQL consideres both your hostname and user name in identifying you.
Involves two stages:
Stage 1: The server checks whether or not you are even allowed to connect.
Stage 2: After connect, the server checks each request you issue to see whether or not you have sufficient privileges to perform it.
The server uses user, db and host at both stages of access control.
|
Table name |
user |
db |
host |
|
Scope fields |
host |
host |
host |
|
|
user |
db |
db |
|
|
password |
user |
|
|
Privilege fields |
select_priv |
select_priv |
select_priv |
|
|
insert_priv |
insert_priv |
insert_priv |
|
|
update_priv |
update_priv |
update_priv |
|
|
delete_priv |
delete_priv |
delete_priv |
|
|
index_priv |
index_priv |
index_priv |
|
|
alter_priv |
alter_priv |
alter_priv |
|
|
create_priv |
create_priv |
create_priv |
|
|
drop_priv |
drop_priv |
drop_priv |
|
|
grant_priv |
grant_priv |
grant_priv |
|
|
reload_priv |
|
|
|
|
shutdown_priv |
|
|
|
|
process_priv |
|
|
|
|
file_priv |
|
|
For the second stage of access control, the server may, if the request involves tables, additionally consult the tables_priv and columns_priv:
|
Table Name |
tables_priv |
columns_priv |
|---|---|---|
|
Scope fields |
host |
host |
|
|
db |
db |
|
|
user |
user |
|
|
table_name |
table_name |
|
|
|
column_name |
|
Privilege fields |
table_priv |
column_priv |
|
|
column_priv |
|
|
Other fields |
timestamp |
timestamp |
|
|
grantor |
|
|
Scope Fields |
|
|---|---|
|
host |
CHAR(60) |
|
user |
CHAR(16) |
|
password |
CHAR(16) |
|
db |
CHAR(64) and CHAR(60) for tables_priv and columns_priv tables. |
|
The default value for each string is the empty string. |
|
In the user, db and host tables all privilege fields are declared as ENUM('Y','N') - The defaul is 'N'.
|
Table name |
Field name |
Possible set elements |
|---|---|---|
|
tables_priv |
table_priv |
'Select', 'Insert', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter' |
|
tables_priv |
column_priv |
'Select', 'Insert', 'Delete', 'References' |
|
columns_priv |
column_priv |
'Select', 'Insert', 'Delete', 'References' |
...
A string is a sequence of characters, surrounded by either single quote (´'´) or double quote (´´) characters.
Escape sequences:
|
|
Desc |
|---|---|
|
\0 |
An ASCII 0 (NUL) character. |
|
\n |
A newline character. |
|
\t |
A tab character. |
|
\r |
A carriage return character. |
|
\b |
A backspace character. |
|
\' |
A single quote (´ ' ´) character. |
|
\ |
A double quote (´ ´) character. |
|
\\ |
A backslash (´\´) character. |
|
\% |
A ´%´ character. This is used to search for literal instances of ´%´ in contexts where ´%´ would otherwise be intercepted as a wildcard character. |
|
\_ |
A '_' character. This is used to search for literal instances of '_' in contexts where '_' would otherwise be interpreted as a wildcard character. |
Integers are represented as a sequence of digits. Floats use '.' as a decimal separator. Either type of number may be preceded by '-' to indicate a negative value.
In number context acts like an 64 bit precision. In string context these acts like string where each pair of hex digits is converted to a character.
Hexadecimal strings is often used by ODBC to give values for BLOB columns.
Are represented by \N.
|
Indentifier |
Max length |
Allowed characters |
|---|---|---|
|
Database |
64 |
Any character that is allowed |
|
Table |
64 |
|
|
Column |
64 |
All characters |
|
Alias |
255 |
All characters |
|
You can't have ASCII(0) or ASCII(255) in an identifier. |
||
If the identifier is a restricted word of contains special characters you must always quote it with ' when you use it.
In MySQL you can refer to a column using any of the following forms:
|
Column reference |
Meaning |
|---|---|
|
col_name |
Column col_name from whichever table used in the query contains a column of that name. |
|
tbl_name.col_name |
Column col_name from table tbl_name of the current database. |
|
db_name.tbl_name.col_name |
Column name from table tbl_name of the database db_name. This form is available in MySQL 3.22 or later. |
|
'column_name' |
A column that is that a keyword od contains special characters. |
The case sensitivity of the underlying operating system determines the case sensitivity of the database and tables names.
Aliases on tables are case sensitive.
Aliases on columns are case insensitive.
Syntax: @variablename. Consists in any alphanumeric characters from the current character set. Variables don´t have to be inicailized. They contains NULL by default and can store an integer, real or a string value.
|
M |
Maximum display size. The maximum legal size is 255. |
|
D |
Applies to floating-point types and indicate the number of digits following the decimal point. The maximum possible value is 30, but should be no greater than M-2. |
|
|
Square brackets indicate parts of type specifiers that are optional. |
|
|
If you specify ZEROFILL for a column, MySQL will automatically ad the UNSIGNED attribute to the column. |
|
Date and time types |
|
|---|---|
|
Type |
Description |
|
DATE |
'1000-01-01' to '9999-12-31'. MySQL
displays DATE values in 'YYYY-MM-DD'
format, but allows you to assign values to DATE
columns using either strings or numbers.
|
|
DATETIME |
'1000-01-01 00:00:00' to
'9999-12-31 23:59:59'. MySQL
displays DATETIME values in 'YYYY-MM-DD
HH:MM:SS' format, but allows you to assign values to
DATETIME columns using either strings or numbers.
|
|
TIMESTAMP [(M)] |
'1970-01-01 00:00:00' to sometime in the year 2037.
MySQL displays TIMESTAMP values in
YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD
or YYMMDD format, depending on whether M
is 14 (or missing), 12, 8
or 6, but allows you to assign values to TIMESTAMP
columns using either strings or numbers. A TIMESTAMP
column is useful for recording the date and time of an INSERT
or UPDATE operation because it is automatically set
to the date and time of the most recent operation if you don't
give it a value yourself. You can also set it to the current date
and time by assigning it a NULL value. |
|
TIME |
'-838:59:59'
to '838:59:59'. MySQL displays TIME
values in 'HH:MM:SS' format, but allows you to
assign values to TIME columns using either strings
or numbers. |
|
YEAR [(2/4)] |
1901
to 2155, and 0000 in the 4 year format
and 1970-2069 if you use the 2 digit format (70-69). MySQL
displays YEAR values in YYYY format,
but allows you to assign values to YEAR columns
using either strings or numbers. (The YEAR type is
new in MySQL 3.22.)
|
|
String (characters) types |
|
|---|---|
|
Type |
Description |
|
CHAR(M) [BINARY] |
M is 1 to 255 characters. Trailing spaces
are removed when the value is retrieved. CHAR values
are sorted and compared in case-insensitive fashion according to
the default character set unless the BINARY keyword
is given. NATIONAL CHAR (short form NCHAR)
is the ANSI SQL way to define that a CHAR column should use the
default CHARACTER set. This is default in MySQL.
CHAR is a shorthand for CHARACTER.
|
|
[NATIONAL] VARCHAR(M) [BINARY] |
M
is 1 to 255 characters. VARCHAR values are sorted
and compared in case-insensitive fashion unless the BINARY
keyword is given. VARCHAR is a shorthand for
CHARACTER VARYING.
|
|
BLOB or TEXT
column with a maximum length of 255 (2^8 - 1) characters. |
|
BLOB or TEXT
column with a maximum length of 65535 (2^16 - 1) characters. |
|
BLOB or TEXT
column with a maximum length of 16777215 (2^24 - 1) characters. |
|
BLOB or TEXT
column with a maximum length of 4294967295 (2^32 - 1) characters. |
|
'value1',
'value2', ..., or NULL. An
ENUM can have a maximum of 65535 distinct values.
|
|
'value1', 'value2', ...
A SET can have a maximum of 64 members.
|
All MySQL column types can be indexed. A table may have up to 16 indexes. The maximum index length is 256 bytes. An index may consist of uo to 15 columns.
|
Other vendor type |
MySQL type |
|---|---|
|
BINARY (NUM) |
CHAR(NUM) BINARY |
|
CHAR VARYING(NUM) |
VARCHAR(NUM) |
|
FLOAT4 |
FLOAT |
|
FLOAT8 |
DOUBLE |
|
INT1 |
TINYINT |
|
INT2 |
SMALLINT |
|
INT3 |
MEDIUMINT |
|
INT4 |
INT |
|
INT8 |
BIGINT |
|
LONG VARBINARY |
MEDIUMBLOB |
|
LONG VARCHAR |
MEDIUMTEXT |
|
MIDDLEINT |
MEDIUMINT |
|
VARBINARY(NUM) |
VARCHAR(NUM) BINARY |
( ... )
The usual arithmetic operators are available. Note that in the
case of -, + and *, the result
is calculated with BIGINT (64-bit) precision if both
arguments are integers!
All logical functions return 1 (TRUE) or 0
(FALSE).
|
Operator |
Description |
Example |
|---|---|---|
|
1
if the argument is 0, otherwise returns 0.
Exception: NOT NULL returns NULL.
|
mysql> select NOT 1;
-> 0
mysql> select NOT NULL;
-> NULL
mysql> select ! (1+1);
-> 0
mysql> select ! 1+1;-> 1 1
because the expression evaluates the same way as (!1)+1.
|
|
1
if either argument is not 0 and not NULL.
|
mysql> select 1 || 0;
-> 1
mysql> select 0 || 0;
-> 0
mysql> select 1 || NULL;
-> 1
|
0
if either argument is 0 or NULL,
otherwise returns 1.
|
mysql> select 1 && NULL;
-> 0
mysql> select 1 && 0;
-> 0
|
Comparison operations result in a value of 1 (TRUE),
0 (FALSE) or NULL.
Normally, if any expression in a string comparison is case sensitive, the comparison is performed in case-sensitive fashion.
expr LIKE pat [ESCAPE 'escape-char']
1 (TRUE) or 0
(FALSE). With LIKE you can use the following two
wildcard characters in the pattern:
|
|
Matches any number of characters, even zero characters |
|
|
Matches exactly one character |
mysql> select 'David!' LIKE 'David_';
-> 1
mysql> select 'David!' LIKE '%D%v%';
-> 1
ESCAPE
character, `\' is assumed:
|
|
Matches one |
|
|
Matches one |
mysql> select 'David!' LIKE 'David\_';
-> 0
mysql> select 'David_' LIKE 'David\_';
-> 1
ESCAPE
clause:
mysql> select 'David_' LIKE 'David|_' ESCAPE '|';
-> 1
LIKE is allowed on numeric expressions! (This is a
MySQL extension to the ANSI SQL LIKE.)
mysql> select 10 LIKE '1%';
-> 1
LIKE strings.
For example, to search for `\n', specify it as `\\n'.
To search for `\', specify it as `\\\\'
(the backslashes are stripped once by the parser, and another time
when the pattern match is done, leaving a single backslash to be
matched).
expr NOT LIKE pat [ESCAPE 'escape-char']
NOT (expr LIKE pat [ESCAPE 'escape-char']).
expr REGEXP pat
expr RLIKE pat
expr
against a pattern pat. The pattern can be an extended
regular expression. See section H
Description of MySQL regular expression syntax. Returns 1
if expr matches pat, otherwise returns 0.
RLIKE is a synonym for REGEXP, provided
for mSQL compatibility. Note: Because MySQL
uses the C escape syntax in strings (e.g., `\n'), you
must double any `\' that you use in your REGEXP
strings. In MySQL 3.23.4 REGEXP is case
insensitive for normal (not binary) strings.
mysql> select 'Monty!' REGEXP 'm%y%%';
-> 0
mysql> select 'Monty!' REGEXP '.*';
-> 1
mysql> select 'new*\n*line' REGEXP 'new\\*.\\*line';
-> 1
mysql> select "a" REGEXP "A", "a" REGEXP BINARY "A";
-> 1 0
REGEXP and RLIKE use
the current character set (ISO-8859-1 Latin1 by default) when
deciding the type of a character.
expr NOT REGEXP pat
expr NOT RLIKE pat
NOT (expr REGEXP pat).
STRCMP(expr1,expr2)
STRCMP() returns 0 if the strings are the
same, -1 if the first argument is smaller than the
second according to the current sort order, and 1
otherwise.
mysql> select STRCMP('text', 'text2');
-> -1
mysql> select STRCMP('text2', 'text');
-> 1
mysql> select STRCMP('text', 'text');
-> 0BINARY
BINARY operator casts the
string following it to a binary string. This is an easy way to force
a column comparison to be case sensitive even if the column isn't
defined as BINARY or BLOB.
mysql> select "a" = "A";
-> 1
mysql> select BINARY "a" = "A";
-> 0
BINARY was introduced in MySQL 3.23.0
IFNULL(expr1,expr2)
expr1 is not NULL,
IFNULL() returns expr1, else it returns
expr2. IFNULL() returns a numeric or
string value, depending on the context in which it is used.
mysql> select IFNULL(1,0);
-> 1
mysql> select IFNULL(0,10);
-> 0
mysql> select IFNULL(1/0,10);
-> 10
mysql> select IFNULL(1/0,'yes');
-> 'yes'
IF(expr1,expr2,expr3)
expr1 is TRUE (expr1 <> 0 and
expr1 <> NULL) then IF() returns
expr2, else it returns expr3. IF()
returns a numeric or string value, depending on the context in which
it is used.
mysql> select IF(1>2,2,3);
-> 3
mysql> select IF(1<2,'yes','no');
-> 'yes'
mysql> select IF(strcmp('test','test1'),'yes','no');
-> 'no'
expr1 is evaluated as an integer value, which means
that if you are testing floating-point or string values, you should
do so using a comparison operation.
mysql> select IF(0.1,1,0);
-> 0
mysql> select IF(0.1<>0,1,0);
-> 1
IF(0.1)
returns 0 because 0.1 is converted to an
integer value, resulting in a test of IF(0). This may
not be what you expect. In the second case, the comparison tests the
original floating-point value to see whether it is non-zero. The
result of the comparison is used as an integer.
CASE value WHEN [compare-value] THEN result [WHEN
[compare-value] THEN result ...] [ELSE result] END
CASE WHEN [condition] THEN result [WHEN [condition] THEN
result ...] [ELSE result] END
result where
value=compare-value. The second version returns the
result for the first condition which is true. If there was no
matching result value, then the result after ELSE is
returned. If there is no ELSE part then NULL
is returned.
mysql> SELECT CASE 1 WHEN 1 THEN "one" WHEN 2 THEN "two" ELSE "more" END;
-> "one"
mysql> SELECT CASE WHEN 1>0 THEN "true" ELSE "false" END;
-> "true"
mysql> SELECT CASE BINARY "B" when "a" then 1 when "b" then 2 END;
-> NULLAll mathematical functions return NULL in case of an error.
|
Function |
Description |
|---|---|
|
X |
|
-1, 0 or 1, depending on
whether X is negative, zero, or positive.
|
%
operator in C). Returns the remainder of N divided
by M.
|
|
|
X. |
|
X. |
|
X,
rounded to an integer. |
|
X,
rounded to a number with D decimals. If D
is 0, the result will have no decimal point or
fractional part.
|
|
e
(the base of natural logarithms) raised to the power of X. |
X.
If you want the log of a number X to some arbitary
base B, use the formula LOG(X)/LOG(B). |
|
|
X.
|
X
raised to the power of Y.
|
|
X. |
|
|
|
|
X,
where X is given in radians. |
|
X,
where X is given in radians.
|
|
X,
where X is given in radians.
|
|
X,
that is, the value whose cosine is X. Returns NULL
if X is not in the range -1 to 1.
|
|
X,
that is, the value whose sine is X. Returns NULL
if X is not in the range -1 to 1.
|
|
X,
that is, the value whose tangent is X. |
|
X and Y. It is similar to
calculating the arc tangent of Y / X, except that
the signs of both arguments are used to determine the quadrant of
the result.
|
|
X.
|
|
0 to 1.0. If an
integer argument N is specified, it is used as the
seed value.
|
|
|
|
|
LEAST.
MAX() instead of GREATEST.
|
|
X,
converted from radians to degrees.
|
X,
converted from degrees to radians.
|
|
X,
truncated to D decimals. If D is 0,
the result will have no decimal point or fractional part. |
CREATE DATABASE db_name
DROP DATABASE [IF EXISTS] db_name
DROP DATABASE drops all tables in the database and
deletes the database.
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
[table_options] [select_statement]
create_definition:
col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
[PRIMARY KEY] [reference_definition]
or PRIMARY KEY (index_col_name,...)
or KEY [index_name] (index_col_name,...)
or INDEX [index_name] (index_col_name,...)
or UNIQUE [INDEX] [index_name] (index_col_name,...)
or [CONSTRAINT symbol] FOREIGN KEY index_name (index_col_name,...)
[reference_definition]
or CHECK (expr)
type:
TINYINT[(length)] [UNSIGNED] [ZEROFILL]
or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
or INT[(length)] [UNSIGNED] [ZEROFILL]
or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
or CHAR(length) [BINARY]
or VARCHAR(length) [BINARY]
or DATE
or TIME
or TIMESTAMP
or DATETIME
or TINYBLOB
or BLOB
or MEDIUMBLOB
or LONGBLOB
or TINYTEXT
or TEXT
or MEDIUMTEXT
or LONGTEXT
or ENUM(value1,value2,value3,...)
or SET(value1,value2,value3,...)
index_col_name:
col_name [(length)]
reference_definition:
REFERENCES tbl_name [(index_col_name,...)]
[MATCH FULL | MATCH PARTIAL]
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
table_options:
TYPE = {ISAM | MYISAM | HEAP}
or AUTO_INCREMENT = #
or AVG_ROW_LENGTH = #
or CHECKSUM = {0 | 1}
or COMMENT = "string"
or MAX_ROWS = #
or MIN_ROWS = #
or PACK_KEYS = {0 | 1}
or PASSWORD = "string"
or DELAY_KEY_WRITE = {0 | 1}
or ROW_FORMAT= { default | dynamic | static | compressed }
select_statement:
[IGNORE | REPLACE] SELECT ... (Some legal select statement)
CREATE TABLE creates a table with the given name in the
current database.
ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]
alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
or ADD INDEX [index_name] (index_col_name,...)
or ADD PRIMARY KEY (index_col_name,...)
or ADD UNIQUE [index_name] (index_col_name,...)
or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
or CHANGE [COLUMN] old_col_name create_definition
or MODIFY [COLUMN] create_definition
or DROP [COLUMN] col_name
or DROP PRIMARY KEY
or DROP INDEX index_name
or RENAME [AS] new_tbl_name
or table_options
ALTER TABLE allows you to change the structure of an
existing table.
OPTIMIZE TABLE tbl_name
OPTIMZE TABLE should be used if you have deleted a large
part of a table or if you have made many changes to a table with
variable-length rows (tables that have VARCHAR, BLOB
or TEXT columns). Deleted records are maintained in a
linked list and subsequent INSERT operations reuse old
record positions. You can use OPTIMIZE TABLE to reclaim
the unused space.
DROP TABLE [IF EXISTS] tbl_name [, tbl_name,...]
DROP TABLE removes one or more tables. All table data
and the table definition are removed, so be careful
with this command!
In MySQL 3.22 or later, you can use the keywords
IF EXISTS to prevent an error from occurring for tables
that don't exist.
DELETE [LOW_PRIORITY] FROM tbl_name
[WHERE where_definition] [LIMIT rows]
DELETE deletes rows from tbl_name that
satisfy the condition given by where_definition, and
returns the number of records deleted.
If you issue a DELETE with no WHERE
clause, all rows are deleted.
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [HIGH_PRIORITY]
[DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO {OUTFILE | DUMPFILE} 'file_name' export_options]
[FROM table_references
[WHERE where_definition]
[GROUP BY col_name,...]
[HAVING where_definition]
[ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...]
[LIMIT [offset,] rows]
[PROCEDURE procedure_name] ]
SELECT is used to retrieve rows selected from one or
more tables. select_expression indicates the columns you
want to retrieve. SELECT may also be used to retrieve
rows computed without reference to any table.
MySQL supports the following JOIN
syntaxes for use in SELECT statements:
table_reference, table_reference
table_reference [CROSS] JOIN table_reference
table_reference INNER JOIN table_reference
table_reference STRAIGHT_JOIN table_reference
table_reference LEFT [OUTER] JOIN table_reference ON conditional_expr
table_reference LEFT [OUTER] JOIN table_reference USING (column_list)
table_reference NATURAL LEFT [OUTER] JOIN table_reference
{ oj table_reference LEFT OUTER JOIN table_reference ON conditional_expr }
The last LEFT OUTER JOIN syntax shown above exists only
for compatibility with ODBC.
INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES (expression,...),(...),...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name
SET col_name=expression, col_name=expression, ...
INSERT inserts new rows into an existing table. The
INSERT ... VALUES form of the statement inserts rows
based on explicitly-specified values. The INSERT ... SELECT
form inserts rows selected from another table or tables. The INSERT
... VALUES form with multiple value lists is supported in
MySQL 3.22.5 or later. The col_name=expression
syntax is supported in MySQL 3.22.10 or later.
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
VALUES (expression,...)
or REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
SET col_name=expression, col_name=expression,...
REPLACE works exactly like INSERT, except
that if an old record in the table has the same value as a new record
on a unique index, the old record is deleted before the new record is
inserted.
LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY '\t']
[OPTIONALLY] ENCLOSED BY '']
[ESCAPED BY '\\' ]]
[LINES TERMINATED BY '\n']
[IGNORE number LINES]
[(col_name,...)]
The LOAD DATA INFILE statement reads rows from a text
file into a table at a very high speed. If the LOCAL
keyword is specified, the file is read from the client host. If LOCAL
is not specified, the file must be located on the server. (LOCAL
is available in MySQL 3.22.6 or later.)
UPDATE [LOW_PRIORITY] tbl_name SET col_name1=expr1,col_name2=expr2,...
[WHERE where_definition] [LIMIT #]
UPDATE updates columns in existing table rows with new
values. The SET clause indicates which columns to modify
and the values they should be given. The WHERE clause,
if given, specifies which rows should be updated. Otherwise all rows
are updated.
USE db_name
The USE db_name statement tells MySQL
to use the db_name database as the default database for
subsequent queries. The database remains current until the end of the
session, or until another USE statement is issued.
FLUSH flush_option [,flush_option]
You should use the FLUSH command if you want to clear
some of the internal caches MySQL uses. To execute
FLUSH, you must have the reload
privilege.
flush_option can be any of the following:
|
|
Empties the host cache tables. You should flush the host tables
if some of your hosts change IP number or if you get the error
message |
|
|
Closes and reopens the standard and update log files. If you have specified the update log file without an extension, the extension number of the new update log file will be incremented by one relative to the previous file. |
|
|
Reloads the privileges from the grant tables in the |
|
|
Closes all open tables. |
|
|
Resets most status variables to zero. |
You can also access each of the commands shown above with the
mysqladmin utility, using the flush-hosts,
flush-logs, reload or flush-tables
commands.
KILL thread_id
Each connection to mysqld runs in a separate thread. You
can see which threads are running with the SHOW PROCESSLIST
command, and kill a thread with the KILL thread_id
command.
SHOW DATABASES [LIKE wild] or SHOW TABLES [FROM db_name] [LIKE wild] or SHOW COLUMNS FROM tbl_name [FROM db_name] [LIKE wild] or SHOW INDEX FROM tbl_name [FROM db_name] or SHOW STATUS or SHOW VARIABLES [LIKE wild] or SHOW [FULL] PROCESSLIST or SHOW TABLE STATUS [FROM db_name] [LIKE wild] or SHOW GRANTS FOR user
SHOW provides information about databases, tables,
columns or the server. If the LIKE wild part is used,
the wild string can be a string that uses the SQL `%'
and `_' wildcard characters.
EXPLAIN tbl_name or EXPLAIN SELECT select_options
EXPLAIN tbl_name is a synonym for DESCRIBE
tbl_name or SHOW COLUMNS FROM tbl_name.
When you precede a SELECT statement with the keyword
EXPLAIN, MySQL explains how it would
process the SELECT, providing information about how
tables are joined and in which order.
{DESCRIBE | DESC} tbl_name {col_name | wild}
DESCRIBE provides information about a table's columns.
col_name may be a column name or a string containing the
SQL `%' and `_' wildcard characters.
LOCK TABLES tbl_name [AS alias] {READ | [LOW_PRIORITY] WRITE}
[, tbl_name {READ | [LOW_PRIORITY] WRITE} ...]
...
UNLOCK TABLES
LOCK TABLES locks tables for the current thread. UNLOCK
TABLES releases any locks held by the current thread. All
tables that are locked by the current thread are automatically
unlocked when the thread issues another LOCK TABLES, or
when the connection to the server is closed.
SET [OPTION] SQL_VALUE_OPTION= value, ...
SET OPTION sets various options that affect the
operation of the server or your client. Any option you set remains in
effect until the current session ends, or until you set the option to
a different value.
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON {tbl_name | * | *.* | db_name.*}
TO user_name [IDENTIFIED BY 'password']
[, user_name [IDENTIFIED BY 'password'] ...]
[WITH GRANT OPTION]
REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON {tbl_name | * | *.* | db_name.*}
FROM user_name [, user_name ...]
GRANT is implemented in MySQL 3.22.11
or later. For earlier MySQL versions, the GRANT
statement does nothing.
CREATE [UNIQUE] INDEX index_name ON tbl_name (col_name[(length)],... )
The CREATE INDEX statement doesn't do anything in MySQL
prior to version 3.22. In 3.22 or later, CREATE INDEX is
mapped to an ALTER TABLE statement to create indexes.
Normally, you create all indexes on a table at the time the table
itself is created with CREATE TABLE.
DROP INDEX index_name ON tbl_name
DROP INDEX drops the index named index_name
from the table tbl_name. DROP INDEX doesn't
do anything in MySQL prior to version 3.22. In 3.22
or later, DROP INDEX is mapped to an ALTER TABLE
statement to drop the index.
The MySQL server supports the # to end of
line, -- to end of line and /* in-line or
multiple-line */ comment styles:
mysql> select 1+1; # This comment continues to the end of line mysql> select 1+1; -- This comment continues to the end of line mysql> select 1 /* this is an in-line comment */ + 1; mysql> select 1+ /* this is a multiple-line comment */ 1;
Note that the -- comment style requires you to have at
least one space after the --!
CREATE [AGGREGATE] FUNCTION function_name RETURNS {STRING|REAL|INTEGER}
SONAME shared_library_name
DROP FUNCTION function_name
A user-definable function (UDF) is a way to extend MySQL
with a new function that works like native (built in) MySQL
functions such as ABS() and CONCAT().
AGGREGATE is a new option for MySQL
3.23. An AGGREGATE function works exactly like a native
MySQL GROUP function like SUM
or COUNT().
CREATE FUNCTION saves the function's name, type and
shared library name in the mysql.func system table. You
must have the insert and delete
privileges for the mysql database to create and drop
functions.
All active functions are reloaded each time the server starts,
unless you start mysqld with the --skip-grant-tables
option. In this case, UDF initialization is skipped and UDFs are
unavailable. (An active function is one that has been loaded with
CREATE FUNCTION and not removed with DROP
FUNCTION.)
For instructions on writing user-definable functions, see section
14
Adding new functions to MySQL. For the UDF mechanism to work,
functions must be written in C or C++, your operating system must
support dynamic loading and you must have compiled mysqld
dynamically (not static).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|