SQL _mode = & quot; function: _ MySQL

Source: Internet
Author: User
SQL _modeamp; quot; amp; quot; function: when viewing the discuz source code, you can see SQL _mode = "". I don't know what it is. I guess it is the setting mode, but I don't know what the mode is, so I searched the internet for the role of SQL _mode =:

-- Reprinted

SQL _mode = "", that is, the high performance should be improved if the MySql mode is not set (such as no input detection, error prompt, or syntax mode check), but the following problems exist:
If an inappropriate data is inserted (the error type is abnormal), mysql sets the data as "the best possible data" and does not report an error, for example:
/Number: 0/possible minimum/possible maximum
/String: Empty string/maximum capacity string that can be stored
/The expression is set to: return an available value (1/0-null)
Therefore, the solution is to use the default value for all columns, which is good for performance.


Detailed description of mysql_mode:

In mysql 5, the default values are REAL_AS_FLOAT, PIPES_AS_CONTACT, ANSI_QUOTES, GNORE_SPACE, and ANSI,
In this mode, values that exceed the length of a field are allowed to be inserted. after the value is inserted, a warning rather than an error is returned. when STRICT_TRANS_TABLES is used,
It is an error and a strict warning is given.

NO_AUTO_CREATE_USER

Prevent GRANT from automatically creating new users unless a password is specified. The following are some introductions in the manual.
The following describes all supported modes: · ALLOW_INVALID_DATES do not check all dates in strict mode. Only check the day between the month and the day between 1 and 12. This is important in Web applications when you get the year, month, and day from three different fields and want to exactly save the content inserted by the user (without date verification. This mode applies to DATE and DATETIME columns. It is not suitable for the TIMESTAMP column. the TIMESTAMP column requires the verification date. After the strict mode is enabled, the server requires valid months and days, not only in the range of 1 to 12 and 1 to 31, respectively. For example, '2017-04-31 'is valid when strict mode is disabled, but it is invalid when strict mode is enabled. ALLOW_INVALID_DATES should also be enabled to allow the masking of fixed dates in strict mode. · ANSI_QUOTES regards 'as an identifier quotation mark ('''). do not treat it as a string quotation mark character. In ANSI mode, you can still use ''' to reference the identifier. When ANSI_QUOTES is enabled, you cannot use double quotation marks to reference strings because it is interpreted as an identifier. · ERROR_FOR_pISION_BY_ZERO is in strict mode. during INSERT or UPDATE, if it is divided by zero (or MOD (X, 0), an error is generated (otherwise it is a warning ). If this mode is not provided, MySQL returns NULL if it is divided by zero. If insert ignore or update ignore is used, MySQL generates a zero division warning, but the operation result is NULL. · The priority of the HIGH_NOT_PRECEDENCENOT operator is that expressions such as NOT a BETWEEN B AND c are interpreted as NOT (a BETWEEN B AND c ). In some earlier versions of MySQL, the expression is interpreted as (NOT a) BETWEEN B AND c. Enable the HIGH_NOT_PRECEDENCESQL mode to obtain results with a higher priority.
mysql>SET sql_mode = ‘’;
mysql>SELECT NOT 1 BETWEEN -5 AND 5;
        -> 0
mysql>SET sql_mode = ‘broken_not’;
mysql>SELECT NOT 1 BETWEEN -5 AND 5;
        -> 1
· IGNORE_SPACE allows space between the function name and. All function names are considered as saved words. The result is that if you want to access the database, table, or column name that is saved as a word, you must reference it. For example, because there is a USER () function, the user table name in the mysql database and the User column in the table are saved, so you must reference them:
SELECT "User" FROM mysql."user";
· NO_AUTO_CREATE_USER prevents GRANT from automatically creating new users unless a password is specified. · NO_AUTO_VALUE_ON_ZERONO_AUTO_VALUE_ON_ZERO affects the processing of AUTO_INCREMENT columns. Generally, you can insert NULL or 0 to this column to generate the next serial number. NO_AUTO_VALUE_ON_ZERO disables 0, so only NULL can generate the next serial number. This mode is useful if you save 0 to the AUTO_INCREMENT column of the table. (This convention is not recommended ). For example, if you use MysqldumpDump the table and reload it. MySQL generates a new serial number when it encounters a value of 0. the contents of the generated table are different from those of the dump table. Enable NO_AUTO_VALUE_ON_ZERO before reloading the dump file to solve this problem. MysqldumpThe output automatically contains the statement that enables NO_AUTO_VALUE_ON_ZERO. · NO_BACKSLASH_ESCAPES disables the backslash ('') as the exit character in the string. If this mode is enabled, the backslash is a common character. · When creating a table, NO_DIR_IN_CREATE ignores all index directory and data directory commands. This option is useful for slave replication servers. · NO_ENGINE_SUBSTITUTION if the required storage engine is disabled or not compiled, the storage engine can be replaced automatically. · NO_FIELD_OPTIONS do not print MySQL special column options in the output of show create table. This mode is used in portability mode Mysqldump. · NO_KEY_OPTIONS do not print the MySQL dedicated index option in the output of show create table. This mode is used in portability mode Mysqldump. · NO_TABLE_OPTIONS do not print the MySQL special TABLE option (such as ENGINE) in the output of show create table ). This mode is used in portability mode Mysqldump. · NO_UNSIGNED_SUBTRACTION in the subtraction operation, if an operand has no symbol, do not mark the result as UNSIGNED. Note that the unsigned bigint cannot be 100% used in context. · NO_ZERO_DATE is in strict mode. do not use '2017-00-00 'as a valid date. You can still use the IGNORE option to insert a zero date. In non-strict mode, this date is acceptable, but a warning is generated. · NO_ZERO_IN_DATE is in strict mode and the date with the month or day part 0 is not accepted. If the IGNORE option is used, we insert '2017-00-00 'for a similar date ′. In non-strict mode, this date is acceptable, but a warning is generated. · ONLY_FULL_GROUP_BY do not point the query in the group by section to an unselected column. · PIPES_AS_CONCAT treats | as a string connection operator (+) (same as CONCAT (), not as OR. · REAL_AS_FLOAT treats REAL as a synonym for FLOAT, rather than a synonym for DOUBLE. · STRICT_TRANS_TABLES enables strict mode for all storage engines. The invalid data value is denied. Detailed descriptions are provided later. · STRICT_TRANS_TABLES enable strict mode for the transaction storage engine, or enable strict mode for the non-transaction storage engine. Detailed descriptions are provided later. Strictly control how MySQL processes illegal or lost input values. One value can be invalid for several reasons. For example, the data type is incorrect. it is not suitable for columns or is out of range. If the newly inserted row does not contain a column that does not display the value defined by the DEFAULT clause, the value is lost. When the STRICT_ALL_TABLES or STRICT_TRANS_TABLES mode is enabled for a transaction table, an error occurs if the statement contains an invalid or missing value. The statement is abandoned and rolled. For non-transaction tables, if the 1st rows inserted or updated have bad values, the two modes share the same behavior. The statement is abandoned and the table remains unchanged. If a statement inserts or modifies multiple rows with a bad value of 2nd or later, the result depends on which strict option is enabled: · for STRICT_ALL_TABLES, MySQL returns an error and ignores the remaining rows. However, in this case, the previous row has been inserted or updated. This indicates that you can update some data, which may not be what you want. To avoid this, it is best to use a single row statement, because you can give up without changing the table. · For STRICT_TRANS_TABLES, MySQL Converts invalid values to valid values closest to the column and inserts the adjusted values. If the value is lost, MySQL inserts an implicit default value in the column. In any case, MySQL generates a warning instead of an error and continues to execute the statement. Describes the implicit default values. Invalid date is not allowed in strict mode, for example, '2017-04-31 ′. It does not allow the date to use the "zero" part, for example, '2017-04-00' or "zero" date. To disable it, enable the NO_ZERO_IN_DATE and NO_ZERO_DATE SQL modes based on the strict mode. If you do not use the strict mode (that is, do not enable STRICT_TRANS_TABLES or STRICT_ALL_TABLES mode), MySQL inserts the adjusted value and provides a warning for invalid or lost values. In strict mode, you can use insert ignore or update ignore. The following special modes quickly combine the modes listed above. This includes all the mode values in most of the latest MySQL versions. In the old version, the combination mode does not include any unsuitable mode values in the new version. · ANSI is equivalent to REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, and IGNORE_SPACE. · DB2 is equivalent to PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, and NO_FIELD_OPTIONS. · MAXDB is equivalent to PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, and NO_AUTO_CREATE_USER. · MSSQL is equivalent to PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, and NO_FIELD_OPTIONS. · MYSQL323 is equivalent to NO_FIELD_OPTIONS and HIGH_NOT_PRECEDENCE. · MYSQL40 is equivalent to NO_FIELD_OPTIONS and HIGH_NOT_PRECEDENCE. · ORACLE is equivalent to PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, and NO_AUTO_CREATE_USER. · POSTGRESQL is equivalent to PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, and NO_FIELD_OPTIONS. · TRADITIONAL

Equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_pISION_BY_ZERO, NO_AUTO_CREATE_USER

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.