The sql_mode setting of mysql and the meaning analysis of each value

1. Query sql_mode

select @@GLOBAL.sql_mode
-- 或
select @@SESSION.sql_mode
-- 或
select @@sql_mode

Insert picture description here

2. Set sql_mode

Set by command

SET GLOBAL sql_mode = 'modes...';
-- 或
SET SESSION sql_mode = 'modes...';

Set in the configuration file Set
[mysqld] under
[mysqld] in /etc/my.cnf

sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3. Common values ​​of sql_mode

ONLY_FULL_GROUP_BY
For GROUP BY aggregation operations, if the column in the SELECT does not appear in the GROUP BY, then this SQL is illegal, because the column is not in the GROUP BY clause

NO_AUTO_VALUE_ON_ZERO
This value affects the insertion of self-growing columns. By default, inserting 0 or NULL means that the next self-increasing value is generated. If the user wants to insert a value of 0, and the column is self-growing, then this option is useful.

STRICT_TRANS_TABLES
In this mode, if a value cannot be inserted into a transaction, the current operation is interrupted, and there is no restriction on non-transactional tables

NO_ZERO_IN_DATE
In strict mode, zero days and months are not allowed

NO_ZERO_DATE
set this value, mysql database does not allow to insert zero date, inserting zero date will throw an error instead of a warning

ERROR_FOR_DIVISION_BY_ZERO
In the insert or update process, if the data is divided by zero, an error is generated instead of a warning. If this mode is not given, Mysql returns NULL when the data is divided by zero

NO_AUTO_CREATE_USER
prohibits GRANT from creating users with empty passwords

NO_ENGINE_SUBSTITUTION
If the required storage engine is disabled or not compiled, then an error is thrown. When this value is not set, replace with the default storage engine and throw an exception

PIPES_AS_CONCAT
regards "||" as a string concatenation operator instead of an OR operator, which is the same as the Oracle database, and is similar to the string concatenation function Concat

ANSI_QUOTES After
enabling ANSI_QUOTES, you cannot use double quotes to quote a string because it is interpreted as an identifier

Guess you like

Origin blog.csdn.net/qq_37823979/article/details/107252060