MySQL's sql_mode analysis and settings

https://blog.csdn.net/hhq163/article/details/54140286

https://blog.csdn.net/ccccalculator/article/details/70432123

After upgrading mysql, the error is actually used. When updating, it prompts that the timestamp type is wrong, and it prompts that there is no default value error.

It turns out that mysql has improved security measures, the original 0000-00-00 is not allowed, and the default value must also be acquired and set

Need to change a bit, but haven't found a quick way to change it, so I have to change the mysql settings first:

1. View sql_mode

mysql> select @@sql_mode;  

 

Second, the meaning of the sql_mode value:

ONLY_FULL_GROUP_BY:

For the GROUP BY aggregation operation, if the column in the SELECT does not appear in the GROUP BY, then this SQL will be considered illegal, because the column is not in the GROUP BY clause

 

STRICT_TRANS_TABLES:

In this mode, if a value cannot be inserted into a transactional table, the current operation is interrupted, and no restrictions are imposed on non-transactional tables

 

NO_ZERO_IN_DATE:

In strict mode, dates with a month or day part of 0 are not accepted. If the IGNORE option is used, we insert '0000-00-00' for similar dates. In non-strict mode, the date is acceptable, but a warning is generated.

 

NO_ZERO_DATE:

In strict mode, do not use '0000-00-00' as a valid date. You can still insert zero dates with the IGNORE option. In non-strict mode, the date is acceptable, but a warning is generated

 

ERROR_FOR_DIVISION_BY_ZERO:

In strict mode, during an INSERT or UPDATE, if division by zero (or MOD(X, 0) ) produces an error (otherwise a warning). If this mode is not given, MySQL returns NULL on division by zero. If used in INSERT IGNORE or UPDATE IGNORE, MySQL generates a division-by-zero warning, but the result of the operation is NULL.

 

NO_AUTO_CREATE_USER

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

 

NO_ENGINE_SUBSTITUTION:

Throws an error if the required storage engine is disabled or not compiled. When this value is not set, the default storage engine is used instead and an exception is thrown

 

3. Change my.conf

remove the red above

#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode='ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

 

4. Restart

mysql.serve restart

systemctl restart mysqlnd

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324632370&siteId=291194637