I noticed strange MySQL behaviour on projects staging server. Given:
create table test_table
(
id int auto_increment,
name varchar(64) not null,
constraint test_table_pk
primary key (id)
);
insert into test_table (id, name)
VALUES (3, 'value 3');
insert into test_table (id, name)
VALUES (5, 'value 5');
insert into test_table (id, name)
VALUES ('value 6 id', 'value 6');
select *
from test_table;
Results:
mysql> select * from test_table;
+----+---------+
| id | name |
+----+---------+
| 3 | value 3 |
| 5 | value 5 |
| 6 | value 6 |
+----+---------+
2 rows in set (0.01 sec)
First two insert statements works fine as expected. What's the magic behind the third one? It works and it seems incorrect type value is replaced with auto increment value. I'm trying to create docker version of the DB server. But I can't find what's config option to enable this behaviour. The third insert statement is rejected by docker DB instance with error message:
Incorrect Integer value: 'value 6 id' for column 'id'
mysql> SHOW VARIABLES LIKE 'version';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| version | 5.7.27-30 |
+---------------+-----------+
1 row in set (0.01 sec)
UPDATE
On Staging server:
show variables like '%sql_mode%';
Returns:
IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
My docker-compose.yaml
version: "3.8"
services:
db:
image: percona/percona-server:5.7.27
volumes:
-db-data:/var/lib/mysql
env_file:
- ./db.env
command:
--sql_mode=IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
ports:
- "3306:3306"
flyway:
image: flyway/flyway:7.15.0
command: migrate
volumes:
- ./../../sql/migrations:/flyway/sql
- ./flyway/conf:/flyway/conf
depends_on:
-db
volumes:
db-data:
Any ideas? Thank you