Andrew Newby Andrew Newby - 3 years ago 162
MySQL Question

sql_mode not updating, even though I've changed it in my.cnf

I'm trying to tweak a database that we moved from a mySQL 5.5 server, to a 5.7 server. It's complaining about the date being

0000-00-00
format. I'm trying to fix this, but I can't get past the errors.

In my.cnf, I have:

sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,TRADITIONAL,ALLOW_INVALID_DATES


I restart mySQL, and then do this in phpmyadmin:

SHOW VARIABLES LIKE 'sql_mode'


But it shows a totally wrong/different list!

sql_mode
STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


What am I doing wrong? This is driving me nuts!

Answer Source

According to the manual, TRADITIONAL includes several other modes:

TRADITIONAL

Before MySQL 5.7.4, and in MySQL 5.7.8 and later, TRADITIONAL is equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, and NO_ENGINE_SUBSTITUTION.

From MySQL 5.7.4 though 5.7.7, TRADITIONAL is equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_AUTO_CREATE_USER, and NO_ENGINE_SUBSTITUTION. The NO_ZERO_IN_DATE, NO_ZERO_DATE, and ERROR_FOR_DIVISION_BY_ZERO modes are not named because in those versions their effects are included in the effects of strict SQL mode (STRICT_ALL_TABLES or STRICT_TRANS_TABLES). Thus, the effects of TRADITIONAL are the same in all MySQL 5.7 versions (and the same as in MySQL 5.6). For additional discussion, see SQL Mode Changes in MySQL 5.7.

So the expansion of the mode is expected and your two modes are equivalent for MySQL 5.7.8+. The sql mode setting is actually evaluated: you can see e.g. that your final mode includes the non-default ALLOW_INVALID_DATES, as defined in your configuration file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download