1

I'm trying to disable STRICT_TRANS_TABLES on MySQL 5.7.34 and, no matter what I do, the option is always enabled. I put manually on my.cnf sql_mode=NO_ENGINE_SUBSTITUTION and no other modes, when I restarted the service, the

SELECT @@sql_mode

returned

STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION.

No matter what modes I put, excluding STRICT_TRANS_TABLES, it's always appending this option to the ones I choose.

But, if I query

SHOW GLOBAL VARIABLES WHERE variable_name = 'sql_mode'

, it shows the value that I put without STRICT_TRANS_TABLES.

I need to disable this, as ODI repositories has this requirements when installing it with MySQL as the DBMS. What am I missing, is it impossible to disable this option in MySQL 5.7.34?

nbk
  • 8,191
  • 5
  • 13
  • 27

1 Answers1

1

It is definitely possible to change the sql_mode in MySQL 5.7.

I suspect you changed the session setting without changing the global setting. Like this:

mysql> set sql_mode = 'STRICT_TRANS_TABLES';

mysql> select @@sql_mode, @@global.sql_mode; +---------------------+------------------------+ | @@sql_mode | @@global.sql_mode | +---------------------+------------------------+ | STRICT_TRANS_TABLES | NO_ENGINE_SUBSTITUTION | +---------------------+------------------------+

mysql> show session variables like 'sql_mode'; +---------------+---------------------+ | Variable_name | Value | +---------------+---------------------+ | sql_mode | STRICT_TRANS_TABLES | +---------------+---------------------+

mysql> show global variables like 'sql_mode'; +---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | sql_mode | NO_ENGINE_SUBSTITUTION | +---------------+------------------------+

(This example shows the opposite of your settings, the global one is non-strict while my session setting is strict. The point is that they can be different, and setting a session option does not change the global option.)

You said you edited the my.cnf, but there are a few ways this could fail to change the global setting.

You could add the setting under the [client] or [mysql] sections in my.cnf, which would apply only to sessions started by the mysql client, not when other application clients connect. You should make sure to add the line in the [mysqld] section in my.cnf.

Also double-check that there isn't another line in your my.cnf that also sets the sql_mode after the place where you edited it. It's not an error for a given variable to be set more than once in the same file, and the last one that sets a value takes priority.

Also you might have an !include or !includedir directive in your my.cnf that reads an additional options file. The sql_mode could be reset in one of those other files. Read https://dev.mysql.com/doc/refman/5.7/en/option-files.html#option-file-inclusions


All that said, I strongly urge you to fix whatever requires ODI to have non-strict mode. Using non-strict mode can allow invalid queries and will truncate data instead of returning an error. For example when strict mode is not enforced, an integer that is too large to fit in a given data type will be "rounded down":

mysql> create table mytable (id int primary key);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into mytable set id = 4000000000; Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> show warnings; +---------+------+---------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------+ | Warning | 1264 | Out of range value for column 'id' at row 1 | +---------+------+---------------------------------------------+ 1 row in set (0.00 sec)

mysql> select * from mytable; +------------+ | id | +------------+ | 2147483647 | +------------+

That value is the highest value supported by a signed int. So every value higher than 231-1 will be truncated in that way.

The same happens with strings and other data types. Is this what you want? I would call this data corruption.


Re your comment:

You can specify a session variable in your JDBC URL, which should override whatever is configured in my.cnf.

jdbc:mysql://myServer:3306/myschema?user=scott&password=tiger&sessionVariables=sql_mode=NO_ENGINE_SUBSTITUTION

See https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-connp-props-session.html#cj-conn-prop_sessionVariables

But I still think it should not be necessary.

Firstly, I think you have overlooked some global configuration, and I've described several places to look earlier in this answer.

Secondly, it makes no sense that ODI requires non-strict mode. I would open a support request with Oracle to ask why that's necessary.

Bill Karwin
  • 14,693
  • 2
  • 30
  • 42
  • ODI is an Oracle middleware for data integration, it's an enterprise class ELT software. Oracle certifies ODI to be run in MySQL, but it requires that STRICT_TRANS_TABLES be disabled. I'm setting sql_mode option in my.cnf in mysqld session, it respects what I put, but z whatever mode I put, gets appended by STRICT_TRANS_TABLES. I'm completely lost, I already did the RTFM thing and no clues about why it's happening. I tried to set in the command line too, even than, it gets appended. – Leandro Jacques Jul 19 '21 at 01:04
  • Curiously, when I checked from the mysql command line client, it were as I expected, STRICT_TRANS_TABLES was disabled in session and global, but, when I checked from DBeaver, the global had STRICT_TRANS_TABLES disabled, but the session had STRICT_TRANS_TABLES enabled appended to the option I explicitly set in my.cnf. Is JDBC changing it when connecting to the session being created? – Leandro Jacques Jul 19 '21 at 02:41
  • The problem was with ODI's RCU utility that doesn't support native JDBC connection string, instead it uses it's own format that don't permit to pass parameteres in it's connection's string and, for some reason, JDBC MySQL driver opens the new session with some default option that always appends STRICT_TRANS_TABLES. The solution was to use ODI Studio master repository creator tool and use JDBC's native connection string format to pass the sql_modes needed as parameters. – Leandro Jacques Jul 19 '21 at 17:29