Bug #89495 "mysqld --initialize" creates all objects (DD, SYS, etc) in non-strict SQL mode
Submitted: 1 Feb 2018 9:43 Modified: 21 Mar 2018 15:11
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:8.0.4 OS:Any
Assigned to: CPU Architecture:Any

[1 Feb 2018 9:43] Guilhem Bichot
Description:
Didn't check older version. Anyway I think only 8.0 needs a fix.
During installation, one of the very first executed SQL scripts is scripts/mysql_system_tables.sql, which starts with:

set sql_mode='';

Given that MySQL nowadays runs with this as default:
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

It is odd that this script doesn't use it.
But, worse, this script doesn't restore sql_mode to default when it ends, so it influences all other initialization-time SQL scripts which follow it, e.g. scripts/mysql_sys_schema.sql; so all stored procedures created with the latter script store "sql_mode=0" in their definition and whill thus use that mode every time they run, later.

What to fix:
- mysql_system_tables.sql should preferrably use the default sql_mode, or use a fixed value which is closer to the default (containing at least ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES as these are sane defaults which filter bad queries).
- mysql_system_tables_fix.sql has the same problem, should also be fixed
- mysql_sys_schema.sql sets sql_mode to '' and restores it later (so it doesn't pollute other scripts' execution), but it shouldn't set it at all.

Be careful:
please also verify that "mysqld --initialize" always uses the default value of sql_mode specified in sys_vars.cc and does _not_ take into account any other value configured in a defaults file (e.g. my.cnf) or passed on the command line. Indeed, we do not want DD objects to be created with a sql_mode defined by the user. We want them to be created with the factory default, for stability and predictability.

How to repeat:
see above
[5 Mar 2018 8:23] Sivert Sørumgård
Posted by developer:
 
Patch pushed, but state was not changed automatically for some reason. Setting state manually to 'Documenting'.
[21 Mar 2018 15:11] Paul DuBois
Posted by developer:
 
Fixed in 8.0.11.

During data directory initialization, the server created objects
using sql_mode=''. Now the server uses the default sql_mode value
(which, among other settings, includes strict mode).