The Server SQL Mode

The MySQL server can operate in different SQL modes, and 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 validation checks it should perform on the data. This makes it easier to use MySQL in a lot of 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.

ValueVersionMeaning
ANSI_QUOTES4.0.0" is treated 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. An implication of using this mode is that you cannot use double quotes to quote a literal string, because it will be intepreted as an identifier.
IGNORE_SPACE4.0.0You can have any number of 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_ZERO4.1.1NO_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_CREATE4.0.15When creating a table, ignore all INDEX DIRECTORY and DATA DIRECTORY directives. This option is useful on slave replication servers.
NO_FIELD_OPTIONS4.1.1Don't print MySQL field-specific options in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode.
NO_KEY_OPTIONS4.1.1Don't print MySQL index-specific options in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode.
NO_TABLE_OPTIONS4.1.1Don't print MySQL table-specific options (such as ENGINE) in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode.
NO_UNSIGNED_SUBTRACTION4.0.2In subtraction operations, don't mark the result as UNSIGNED if one of the operands is unsigned. Note that this makes UNSIGNED BIGINT not 100 % usable in all contexts. See Cast Functions.
ONLY_FULL_GROUP_BY4.0.0Don't allow queries which in the GROUP BY part refers to a not selected column.
PIPES_AS_CONCAT4.0.0Treat || as a string concatenation operator (same as CONCAT()) rather than as a synonym for OR.
REAL_AS_FLOAT4.0.0Treat 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:

ValueVersionMeaning
ANSI4.1.1REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY. See ANSI mode.
DB24.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS
DB24.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS
MAXDB4.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS
MSSQL4.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS
MYSQL3234.1.1NO_FIELD_OPTIONS
MYSQL404.1.1NO_FIELD_OPTIONS
ORACLE4.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS
POSTGRESQL4.1.1PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS