Import data into MySql with docker-compose

Having a docker-compose setup which involves a Database like Mysql or MariaDB, then at some point you might want to import data into those Databases.

There are several ways to import the data in your docker-compose setup.

  1. Using a volume for import data
  2. Using mysql client from commandline with docker-compose exec
  3. Using phpmyadmin in docker-compose setup
  4. Using a mysql GUI client on the host and connect to the DB in the Docker container

So let’s see how we can do this:

Continue reading “Import data into MySql with docker-compose”

Migrating user table from Mysql to Postgres with Symfony and Doctrine

When using bin/console make:entity on Mysql and then later you switch your application to Postgres and you have a table called user, which you most likely have when using security component of Symfony.
Then you will receive an error because user is a reserved word in Postgres!

An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "dev@dev.de", "[]", "your-encrypted-password", 0]:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"
LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...

Continue reading “Migrating user table from Mysql to Postgres with Symfony and Doctrine”

Docker-compose and Unknown MySQL server host

In case you encounter this error with mysql and your docker-compose setup:

Unknown MySQL server host <mysql-service-name>Code language: HTML, XML (xml)

… and you dont know why because everything seems to be correct.

Then you might have an upgrade problem with mysql because you are reusing an old volume that was created for another mysql version.
This can happen when you use a unspecified tag as mysql:latest (not recommended anyway) and there was a version bump in the official mysql image.
Or you upgraded the mysql container yourself, f.e. from mysql:5.6 to mysql:5.7 and you are reusing the data volume with the mysql files.

Continue reading “Docker-compose and Unknown MySQL server host”