Professional Documents
Culture Documents
In In:: (Database - ... (Database
In In:: (Database - ... (Database
In In:: (Database - ... (Database
alter_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
The database name can be omitted from the first syntax, in which case
the statement applies to the default database.
The CHARACTER SET clause changes the default database character set.
The COLLATE clause changes the default database collation.
http://dev.mysql.com/doc/refman/5.5/en/charset.html, discusses
character set and collation names.
You can see what character sets and collations are available using,
respectively, the SHOW CHARACTER SET and SHOW COLLATION statements. See
[HELP SHOW CHARACTER SET], and [HELP SHOW COLLATION], for more
information.
The syntax that includes the UPGRADE DATA DIRECTORY NAME clause updates
the name of the directory associated with the database to use the
encoding implemented in MySQL 5.1 for mapping database names to
database directory names (see
http://dev.mysql.com/doc/refman/5.5/en/identifier-mapping.html). This
clause is for use under these conditions:
For example, if a database in MySQL 5.0 has the name a-b-c, the name
contains instances of the - (dash) character. In MySQL 5.0, the
database directory is also named a-b-c, which is not necessarily safe
for all file systems. In MySQL 5.1 and later, the same database name is
encoded as a@002db@002dc to produce a file system-neutral directory
name.
After executing this statement, you can refer to the database as a-b-c
without the special #mysql50# prefix.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-database.html
Syntax:
ALTER
[DEFINER = { user | CURRENT_USER }]
EVENT event_name
[ON SCHEDULE schedule]
[ON COMPLETION [NOT] PRESERVE]
[RENAME TO new_event_name]
[ENABLE | DISABLE | DISABLE ON SLAVE]
[COMMENT 'comment']
[DO event_body]
Any user can alter an event defined on a database for which that user
has the EVENT privilege. When a user executes a successful ALTER EVENT
statement, that user becomes the definer for the affected event.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-event.html
Syntax:
ALTER FUNCTION func_name [characteristic ...]
characteristic:
COMMENT 'string'
| LANGUAGE SQL
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
You must have the ALTER ROUTINE privilege for the function. (That
privilege is granted automatically to the function creator.) If binary
logging is enabled, the ALTER FUNCTION statement might also require the
SUPER privilege, as described in
http://dev.mysql.com/doc/refman/5.5/en/stored-programs-logging.html.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-function.html
Syntax:
ALTER LOGFILE GROUP logfile_group
ADD UNDOFILE 'file_name'
[INITIAL_SIZE [=] size]
[WAIT]
ENGINE [=] engine_name
*Note*:
All NDB Cluster Disk Data objects share the same namespace. This means
that each Disk Data object must be uniquely named (and not merely each
Disk Data object of a given type). For example, you cannot have a
tablespace and an undo log file with the same name, or an undo log file
and a data file with the same name.
The optional INITIAL_SIZE parameter sets the UNDO file's initial size
in bytes; if not specified, the initial size defaults to 134217728 (128
MB). Prior to MySQL NDB Cluster 7.2.14, this value was required to be
specified using digits (Bug #13116514, Bug #16104705, Bug #62858); in
MySQL NDB Cluster 7.2.14 and later, you may optionally follow size with
a one-letter abbreviation for an order of magnitude, similar to those
used in my.cnf. Generally, this is one of the letters M (megabytes) or
G (gigabytes).
*Note*:
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-logfile-group.html
Syntax:
ALTER PROCEDURE proc_name [characteristic ...]
characteristic:
COMMENT 'string'
| LANGUAGE SQL
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
This statement can be used to change the characteristics of a stored
procedure. More than one change may be specified in an ALTER PROCEDURE
statement. However, you cannot change the parameters or body of a
stored procedure using this statement; to make such changes, you must
drop and re-create the procedure using DROP PROCEDURE and CREATE
PROCEDURE.
You must have the ALTER ROUTINE privilege for the procedure. By
default, that privilege is granted automatically to the procedure
creator. This behavior can be changed by disabling the
automatic_sp_privileges system variable. See
http://dev.mysql.com/doc/refman/5.5/en/stored-routines-privileges.html.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-procedure.html
Syntax:
ALTER SERVER server_name
OPTIONS (option [, option] ...)
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-server.html
Syntax:
ALTER [ONLINE|OFFLINE] [IGNORE] TABLE tbl_name
[alter_specification [, alter_specification] ...]
[partition_options]
alter_specification:
table_options
| ADD [COLUMN] col_name column_definition
[FIRST | AFTER col_name]
| ADD [COLUMN] (col_name column_definition,...)
| ADD {INDEX|KEY} [index_name]
[index_type] (index_col_name,...) [index_option] ...
| ADD [CONSTRAINT [symbol]] PRIMARY KEY
[index_type] (index_col_name,...) [index_option] ...
| ADD [CONSTRAINT [symbol]]
UNIQUE [INDEX|KEY] [index_name]
[index_type] (index_col_name,...) [index_option] ...
| ADD FULLTEXT [INDEX|KEY] [index_name]
(index_col_name,...) [index_option] ...
| ADD SPATIAL [INDEX|KEY] [index_name]
(index_col_name,...) [index_option] ...
| ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (index_col_name,...)
reference_definition
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name new_col_name column_definition
[FIRST|AFTER col_name]
| [DEFAULT] CHARACTER SET [=] charset_name [COLLATE [=] collation_name]
| CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
| {DISABLE|ENABLE} KEYS
| {DISCARD|IMPORT} TABLESPACE
| DROP [COLUMN] col_name
| DROP {INDEX|KEY} index_name
| DROP PRIMARY KEY
| DROP FOREIGN KEY fk_symbol
| FORCE
| MODIFY [COLUMN] col_name column_definition
[FIRST | AFTER col_name]
| ORDER BY col_name [, col_name] ...
| RENAME [TO|AS] new_tbl_name
| ADD PARTITION (partition_definition)
| DROP PARTITION partition_names
| TRUNCATE PARTITION {partition_names | ALL}
| COALESCE PARTITION number
| REORGANIZE PARTITION [partition_names INTO (partition_definitions)]
| ANALYZE PARTITION {partition_names | ALL}
| CHECK PARTITION {partition_names | ALL}
| OPTIMIZE PARTITION {partition_names | ALL}
| REBUILD PARTITION {partition_names | ALL}
| REPAIR PARTITION {partition_names | ALL}
| PARTITION BY partitioning_expression
| REMOVE PARTITIONING
index_col_name:
col_name [(length)] [ASC | DESC]
index_type:
USING {BTREE | HASH}
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
table_options:
table_option [[,] table_option] ...
table_option:
AUTO_INCREMENT [=] value
| AVG_ROW_LENGTH [=] value
| [DEFAULT] CHARACTER SET [=] charset_name
| CHECKSUM [=] {0 | 1}
| [DEFAULT] COLLATE [=] collation_name
| COMMENT [=] 'string'
| CONNECTION [=] 'connect_string'
| {DATA|INDEX} DIRECTORY [=] 'absolute path to directory'
| DELAY_KEY_WRITE [=] {0 | 1}
| ENGINE [=] engine_name
| INSERT_METHOD [=] { NO | FIRST | LAST }
| KEY_BLOCK_SIZE [=] value
| MAX_ROWS [=] value
| MIN_ROWS [=] value
| PACK_KEYS [=] {0 | 1 | DEFAULT}
| PASSWORD [=] 'string'
| ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
| TABLESPACE tablespace_name [STORAGE {DISK|MEMORY|DEFAULT}]
| UNION [=] (tbl_name[,tbl_name]...)
ALTER TABLE changes the structure of a table. For example, you can add
or delete columns, create or destroy indexes, change the type of
existing columns, or rename columns or the table itself. You can also
change characteristics such as the storage engine used for the table or
the table comment.
o To use ALTER TABLE, you need ALTER, CREATE, and INSERT privileges for
the table. Renaming a table requires ALTER and DROP on the old table,
ALTER, CREATE, and INSERT on the new table.
o With the mysql_info() C API function, you can find out how many rows
were copied by ALTER TABLE, and (when IGNORE is used) how many rows
were deleted due to duplication of unique key values. See
http://dev.mysql.com/doc/refman/5.5/en/mysql-info.html.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-table.html
Syntax:
ALTER TABLESPACE tablespace_name
{ADD|DROP} DATAFILE 'file_name'
[INITIAL_SIZE [=] size]
[WAIT]
ENGINE [=] engine_name
This statement can be used either to add a new data file, or to drop a
data file from a tablespace.
The ADD DATAFILE variant enables you to specify an initial size using
an INITIAL_SIZE clause, where size is measured in bytes; the default
value is 134217728 (128 MB). Prior to MySQL NDB Cluster 7.2.14, this
value was required to be specified using digits (Bug #13116514, Bug
#16104705, Bug #62858); in MySQL NDB Cluster 7.2.14 and later, you may
optionally follow size with a one-letter abbreviation for an order of
magnitude, similar to those used in my.cnf. Generally, this is one of
the letters M (megabytes) or G (gigabytes).
*Note*:
All NDB Cluster Disk Data objects share the same namespace. This means
that each Disk Data object must be uniquely named (and not merely each
Disk Data object of a given type). For example, you cannot have a
tablespace and an data file with the same name, or an undo log file and
a tablespace with the same name.
Once a data file has been created, its size cannot be changed; however,
you can add more data files to the tablespace using additional ALTER
TABLESPACE ... ADD DATAFILE statements.
Using DROP DATAFILE with ALTER TABLESPACE drops the data file
'file_name' from the tablespace. You cannot drop a data file from a
tablespace which is in use by any table; in other words, the data file
must be empty (no extents used). See
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-disk-data-objects.
html. In addition, any data file to be dropped must previously have
been added to the tablespace with CREATE TABLESPACE or ALTER
TABLESPACE.
Both ALTER TABLESPACE ... ADD DATAFILE and ALTER TABLESPACE ... DROP
DATAFILE require an ENGINE clause which specifies the storage engine
used by the tablespace. Currently, the only accepted values for
engine_name are NDB and NDBCLUSTER.
When ALTER TABLESPACE ... ADD DATAFILE is used with ENGINE = NDB, a
data file is created on each Cluster data node. You can verify that the
data files were created and obtain information about them by querying
the INFORMATION_SCHEMA.FILES table. For example, the following query
shows all data files belonging to the tablespace named newts:
See http://dev.mysql.com/doc/refman/5.5/en/files-table.html.
ALTER TABLESPACE is useful only with Disk Data storage for NDB Cluster.
See
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-disk-data.html.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-tablespace.html
Syntax:
ALTER
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
This statement changes the definition of a view, which must exist. The
syntax is similar to that for CREATE VIEW and the effect is the same as
for CREATE OR REPLACE VIEW. See [HELP CREATE VIEW]. This statement
requires the CREATE VIEW and DROP privileges for the view, and some
privilege for each column referred to in the SELECT statement. ALTER
VIEW is permitted only to the definer or users with the SUPER
privilege.
URL: http://dev.mysql.com/doc/refman/5.5/en/alter-view.html
MySQL supports foreign keys, which let you cross-reference related data
across tables, and foreign key constraints, which help keep this
spread-out data consistent. The essential syntax for a foreign key
constraint definition in a CREATE TABLE or ALTER TABLE statement looks
like this:
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
URL: http://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html
Syntax:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] ...
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
CREATE DATABASE creates a database with the given name. To use this
statement, you need the CREATE privilege for the database. CREATE
SCHEMA is a synonym for CREATE DATABASE.
URL: http://dev.mysql.com/doc/refman/5.5/en/create-database.html
Syntax:
CREATE
[DEFINER = { user | CURRENT_USER }]
EVENT
[IF NOT EXISTS]
event_name
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE | DISABLE ON SLAVE]
[COMMENT 'comment']
DO event_body;
schedule:
AT timestamp [+ INTERVAL interval] ...
| EVERY interval
[STARTS timestamp [+ INTERVAL interval] ...]
[ENDS timestamp [+ INTERVAL interval] ...]
interval:
quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
This statement creates and schedules a new event. The event will not
run unless the Event Scheduler is enabled. For information about
checking Event Scheduler status and enabling it if necessary, see
http://dev.mysql.com/doc/refman/5.5/en/events-configuration.html.
CREATE EVENT requires the EVENT privilege for the schema in which the
event is to be created. It might also require the SUPER privilege,
depending on the DEFINER value, as described later in this section.
o An ON SCHEDULE clause, which determines when and how often the event
executes.
URL: http://dev.mysql.com/doc/refman/5.5/en/create-event.html
URL: http://dev.mysql.com/doc/refman/5.5/en/create-function.html
Syntax:
CREATE [ONLINE|OFFLINE] [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
[index_type]
ON tbl_name (index_col_name,...)
[index_option] ...
index_col_name:
col_name [(length)] [ASC | DESC]
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
index_type:
USING {BTREE | HASH}
URL: http://dev.mysql.com/doc/refman/5.5/en/create-index.html