[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The MySQL server can operate in different SQL modes, and (as of MySQL 4.1) can apply these modes differentially for different clients. This allows applications to tailor server operation to their own requirements.
Modes define what SQL syntax MySQL should support and what kind of data validation checks it should perform. This makes it easier to use MySQL in different environments and to use MySQL together with other database servers.
You can set the default SQL mode by starting mysqld
with the
--sql-mode="modes"
option. Beginning with MySQL 4.1, you can also
change the mode after startup time by setting the sql_mode
variable
with a SET [SESSION|GLOBAL] sql_mode='modes'
statement.
Setting the GLOBAL
variable affects the operation of all clients that
connect from that time on. Setting the SESSION
variable affects only
the current client.
modes
is a list of different modes separated by comma (`,')
characters.
You can retrieve the current mode by issuing a SELECT @@sql_mode
statement. The default value is empty (no modes set).
The value also can be empty
(--sql-mode=""
) if you want to reset it.
The following table lists the supported modes. The Version column indicates when each mode value was implemented.
Value | Version | Meaning | ||
ANSI_QUOTES | 4.0.0 | Treat `"' as an identifier quote character (like the MySQL Server ``' quote character) and not as a string quote character. You can still use ``' to quote identifers in ANSI mode. With ANSI_QUOTES enabled, you cannot use double quotes to quote a literal string, because it will be intepreted as an identifier. |
||
IGNORE_SPACE | 4.0.0 | Allow spaces between a function name and the `(' character. This forces all function names to be treated as reserved words. As a result, if you want to access any database, table, or column name that is a reserved word, you must quote it. For example, because there is a USER() function, the name of the user table in the mysql database and the User column in that table become reserved, so you must quote them: |
SELECT "User" FROM mysql."user"; |
NO_AUTO_VALUE_ON_ZERO
NO_AUTO_VALUE_ON_ZERO
affects handling of AUTO_INCREMENT
columns. Normally, you generate the next sequence number for the column by
inserting either NULL
or 0
into it. NO_AUTO_VALUE_ON_ZERO
suppresses this behavior for 0
so that only NULL
generates
the next sequence number. This mode can be useful if 0
has been
stored in a table's AUTO_INCREMENT
column. (This is not a recommended
practice,
by the way.) For example, if you dump the table with mysqldump
and
then reload it, normally MySQL will generate new sequence numbers when it
encounters the 0
values, resulting in a table with different contents
than the one that was dumped. Enabling NO_AUTO_VALUE_ON_ZERO
before
reloading the dump file solves this problem. (As of MySQL 4.1.1,
mysqldump
automatically includes statements in the dump output to enable
NO_AUTO_VALUE_ON_ZERO
.)
NO_DIR_IN_CREATE
INDEX DIRECTORY
and DATA DIRECTORY
directives. This option is useful on slave replication servers.NO_FIELD_OPTIONS
SHOW CREATE TABLE
. This mode is used by mysqldump
in portability mode.NO_KEY_OPTIONS
SHOW CREATE TABLE
. This mode is used by mysqldump
in portability mode.NO_TABLE_OPTIONS
ENGINE
) in the output of SHOW CREATE TABLE
. This mode is used by mysqldump
in portability mode.NO_UNSIGNED_SUBTRACTION
UNSIGNED
if one of the operands is unsigned. Note that this makes UNSIGNED BIGINT
not 100% usable in all contexts. See section 12.5 Cast Functions.ONLY_FULL_GROUP_BY
GROUP BY
part refers to a not selected column.PIPES_AS_CONCAT
||
as a string concatenation operator (same as CONCAT()
) rather than as a synonym for OR
.REAL_AS_FLOAT
REAL
as a synonym for FLOAT
rather than as a synonym for DOUBLE
.The following special modes are provided as shorthand for combinations of mode values from the preceding table:
Value | Version | Meaning |
ANSI | 4.1.1 | REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY . See section 1.8.3 Running MySQL in ANSI Mode. |
DB2 | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
DB2 | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
MAXDB | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
MSSQL | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
MYSQL323 | 4.1.1 | NO_FIELD_OPTIONS |
MYSQL40 | 4.1.1 | NO_FIELD_OPTIONS |
ORACLE | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
POSTGRESQL | 4.1.1 | PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |