Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 7072

Setting sql_mode command when spinning up mysql docker container

$
0
0

I need to set this global config value in mysql to allow zeros in Date fields, to be automatically set as part of the docker images setup and configuration.

SET GLOBAL sql_mode='ALLOW_INVALID_DATES,NO_ZERO_DATE';

No method I have tried works successfully.

My environment:

  • ubuntu vps, laravel project
  • docker containers (mysql is run as a dependency when I "docker-compose up -d --build nginx" along with redis, etc.)

I tried creating a file "sql_mode.cnf" that contains

SET GLOBAL sql_mode='ALLOW_INVALID_DATES,NO_ZERO_DATE';

and called the file from mysql.prod.dockerfile via docker-compose.prod.yml as follows but it's not working. Possibly some error issues with file access?

Is this even the right method? Is there a better one?

docker-compose.prod.yml (extract):

  mysql:    build:      context: .      dockerfile: mysql.prod.dockerfile    container_name: mysql    ports:      - 3306:3306    environment:      MYSQL_DATABASE: database      MYSQL_USER: datauser      MYSQL_PASSWORD: pwd      MYSQL_ROOT_PASSWORD: pwd    networks:      - laravel

mysql.prod.dockerfile:

FROM mysql:8.0.32COPY sql_mode.cnf /etc/mysql/conf.d/RUN echo "SET GLOBAL sql_mode='ALLOW_INVALID_DATES,NO_ZERO_DATE';" > /docker-entrypoint-initdb.d/init_sql_mode.sql

sql_mode.cnf:

SET GLOBAL sql_mode='ALLOW_INVALID_DATES,NO_ZERO_DATE';

This is the "docker logs mysql" output:

This is the log from running the docker. But the zeroes in date setting did not take. Why?

remote: #3 [internal] load metadata for docker.io/library/mysql:8.0.32remote: #3 DONE 0.0sremote:remote: #4 [1/3] FROM docker.io/library/mysql:8.0.32remote: #4 CACHEDremote:remote: #5 [internal] load build contextremote: #5 transferring context: 94B 0.5s doneremote: #5 DONE 0.6sremote:remote: #6 [2/3] COPY sql_mode.cnf /etc/mysql/conf.d/remote: #6 DONE 0.1sremote:remote: #7 [3/3] RUN echo "SET GLOBAL sql_mode='ALLOW_INVALID_DATES,NO_ZERO_DATE';" > /docker-entrypoint-initdb.d/init_sql_mode.sqlremote: #7 DONE 0.7sremote:remote: #8 exporting to imageremote: #8 exporting layers 0.1s done

Why didn't this work? Is there a better way to do this? I have not found any guides online for how to set this up - are there any?

I would be so grateful for any help - I've worked on this for days :-)


Viewing all articles
Browse latest Browse all 7072

Trending Articles