Posted 4 months ago. Visible to the public.

Using multiple MySQL versions on the same linux machine using docker

We had a card that described how to install multiple mysql versions using mysql-sandbox. Nowadays with the wide adoption of docker it might be easier to use a MySQL docker image for this purpose.

Create a new mysql instance

docker run --name projectname_db -e MYSQL_ROOT_PASSWORD=secret -p "33008:3306" -d --restart unless-stopped mysql:5.7

The port 33008 is a freely chosen free port on the host machine that will be used to establish a connection.
You can see available mysql versions on the docker hub Archive .
The restart policy unless-stopped will also start the database container after a reboot (until you manually stop it).

Connect to DB instance

$ mysql -uroot -psecret -P 33008 -h Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.35 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]>

Make sure to always use the ip instead of localhost (-h so that a tcp connection is used instead of a socket connection.

Configure rails application to use the database

development: adapter: mysql2 database: projectname_development encoding: utf8mb4 collation: utf8mb4_unicode_ci host: username: root password: secret port: 33008 variables: sql_mode: TRADITIONAL

Further commands

docker stop projectname_db # stop the container docker start projectname_db # start the container e.g. after a reboot docker rm projectname_db # remove the container (will not delete the volume of the container) docker volume prune # remove the volume (and all other volumes that are not connected to a container) docker rm -v projectname_db # remove the container including volume in one step

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Daniel Straßner
Last edit:
3 months ago
by Daniel Straßner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Daniel Straßner to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more