Mysql SQL SERVER mode introduction, mysqlsql Server Mode

Source: Internet
Author: User

Mysql SQL SERVER mode introduction, mysqlsql Server Mode

Mysql SQL Server Mode

The MySQL server can operate in different SQL modes, and can apply different modes to different clients. In this way, each application can customize the server operation mode as needed.

The mode defines which SQL syntaxes should be supported by MySQL and which data verification checks should be performed. This makes it easier to use MySQL in different environments and use it with other database servers.

You can use the -- SQL-mode = "modes" option to start mysqld to set the default SQL mode. If you want to reset, this value can also be blank (-- SQL-mode = "").

You can also use the SET [SESSION | GLOBAL] SQL _mode = 'modes 'statement to SET the SQL _mode variable after startup to change the SQL mode. The SUPER permission is required when setting GLOBAL variables, and operations on all clients connected from that time will be affected. Setting SESSION variables only affects the current client. Any client can change its own session SQL _mode value at any time.

Modesis is a series of different modes separated by commas. You can use the SELECT @ SQL _mode statement to query the current mode. The default value is null (NO mode is set ).

Important SQL _mode values

· ANSI

Modify the syntax and behavior to make it more compliant with standard SQL.

· STRICT _ TRANS_TABLES

If the given value cannot be inserted into the transaction table, discard the statement. For non-transaction tables, if the value appears in the 1st rows of a single-row or multi-row statement, the statement is discarded. A more detailed description is provided later in this section.

· TRADITIONAL

Make MySQL acts like a "traditional" SQL database system. A simple description of this mode is to "give an error rather than warning" when an incorrect value is inserted in the column ". Note: if an error is found, immediately discard INSERT/UPDATE. If you use a non-transaction storage engine, this method is not what you want, because the data changes made before an error are not "rolled", and the result is that the update is "only a part ".

This manual refers to the "STRICT mode", indicating at least the mode in which STRICT _ TRANS_TABLES or STRICT _ ALL_TABLES is enabled.

All supported modes are described below:

· 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

Use '"' as an identifier quotation mark ('''). Do not use it as a string quotation mark. 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_DIVISION_BY_ZERO

In strict mode, if the INSERT or UPDATE process 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.

· HIGH _ NOT_PRECEDENCE

The priority of the NOT operator is that the expression, for example, NOT a BETWEEN B AND c, is 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.

Copy codeThe Code is as follows:
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

A space is allowed 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:
Copy codeThe Code is as follows:
SELECT "User" FROM mysql. "user ";

· NO _ AUTO_CREATE_USER

Prevent GRANT from automatically creating new users unless a password is specified.

· NO _ AUTO_VALUE_ON_ZERO

NO_AUTO_VALUE_ON_ZERO affects the processing of the AUTO_INCREMENT column. 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 mysqldump to dump a table and reload the table, 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. Mysqldump automatically includes the NO_AUTO_VALUE_ON_ZERO statement in the output.

· NO _ BACKSLASH_ESCAPES

Disables the backslash ('\') as the exit character in the string. If this mode is enabled, the backslash is a common character.

· NO _ DIR_IN_CREATE

Ignore all index directory And data directory commands when creating a table. This option is useful for slave replication servers.

· NO _ ENGINE_SUBSTITUTION

If the required storage engine is disabled or not compiled, the storage engine cannot be replaced automatically.

· NO _ FIELD_OPTIONS

Do not print the MySQL special column option in the output of show create table. This mode is used for mysqldump in portable mode.

· NO _ KEY_OPTIONS

Do not print MySQL-specific index options in the output of show create table. This mode is used for mysqldump in portable mode.

· 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 for mysqldump in portable mode.

· NO _ UNSIGNED_SUBTRACTION

In a subtraction operation, if an operand has no symbols, do not mark the result as UNSIGNED. Note that the unsigned bigint cannot be 100% used in context. See section 12.8 "Cast functions and operators ".

· NO _ ZERO_DATE

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

In strict mode, the date of month or day 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

| Is treated as a String concatenation operator (+) (same as CONCAT (), not as OR.

· REAL _ AS_FLOAT

Treat REAL as a synonym for FLOAT, rather than a synonym for DOUBLE.

· STRICT _ TRANS_TABLES

Enable 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 the statement inserts or modifies multiple rows and the bad value appears in the 2nd or later rows, 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. Section 13.1.5, "create table Syntax" describes 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. See section 13.5.4.22, "show warnings Syntax ".

Related Article

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.