I have an issue with the official dockerized image of Mariadb.
When my applications tries to make some queries I got the following error :
DB Error: unknown error QUERY : INSERT INTO
It seems this error comes from the SQL_MODE, which is set as follow in this image :
STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION
I have a normal Linux Server and with mariadb installed and i don't have this STRICT_TRANS_TABLES value in my SQL_mode. And my application is working without any problem.
How can I remove the STRICT_TRANS_TABLES value in my container when I run docker-compose with my docker-compose file without the need of a custom dockerfile?
To change the SQL mode at runtime, set the global or session sql_mode system variable using a SET statement: SET GLOBAL sql_mode = 'modes'; SET SESSION sql_mode = 'modes'; Setting the GLOBAL variable requires the SUPER privilege and affects the operation of all clients that connect from that time on.
Execute the following to connect to MariaDB using the command-line client: > docker exec -it mdb mariadb --user root -pPassword123! And that's it! That's all you need to connect to and start using (querying) MariaDB.
You can download a MariaDB image for Docker from the Offical Docker MariaDB, or choose another image that better suits your needs. You can search Docker Hub (the official set of repositories) for an image with this command: Once you have found an image that you want to use, you can download it via Docker.
Getting docker-compose to work with MySQL images is a little tricky, as the database needs too much time to start up. Below is a configuration that starts one application host and one database host.
The most important ways for doing this are using SQL_MODE (controlled by the sql_mode system variable) and OLD_MODE (the old_mode system variable). SQL_MODE is used for getting MariaDB to emulate behavior from other SQL servers, while OLD_MODE is used for emulating behavior from older MariaDB or MySQL versions.
Multiple MariaDB servers running in separate Docker containers can connect to each other using TCP. This is useful for forming a Galera cluster or for replication. When running a cluster or a replication setup via Docker, we will want the containers to use different ports.
In your docker-compose.yml
set command: --sql_mode=""
.
Here is an example:
db-service:
build:
context: .
dockerfile: db.dockerfile
image: example/repo:db
ports:
- "3306:3306"
volumes:
- ./data/db-data:/var/lib/mysql
- ./data/db-init:/docker-entrypoint-initdb.d/
ports:
- "3306:3306"
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: your_database
command: mysqld --sql_mode="" --character-set-server=utf8 --collation-server=utf8_slovenian_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
restart: on-failure
networks:
- yournet
It works fine for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With