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.
Value | Version | Meaning |
ANSI_QUOTES | 4.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_SPACE | 4.0.0 | You 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_ZERO | 4.1.1 | 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 | 4.0.15 | When creating a table, ignore all INDEX DIRECTORY and DATA DIRECTORY directives. This option is useful on slave replication servers. |
NO_FIELD_OPTIONS | 4.1.1 | Don't print MySQL field-specific options in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode. |
NO_KEY_OPTIONS | 4.1.1 | Don't print MySQL index-specific options in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode. |
NO_TABLE_OPTIONS | 4.1.1 | Don't print MySQL table-specific options (such as ENGINE) in the output of SHOW CREATE TABLE. Used by mysqldump in portability mode. |
NO_UNSIGNED_SUBTRACTION | 4.0.2 | In 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_BY | 4.0.0 | Don't allow queries which in the GROUP BY part refers to a not selected column. |
PIPES_AS_CONCAT | 4.0.0 | Treat || as a string concatenation operator (same as CONCAT()) rather than as a synonym for OR. |
REAL_AS_FLOAT | 4.0.0 | Treat 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 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 |