MySQL Setup Procedure for Specific Version [Docker Edition]

Tadashi Shigeoka ·  Tue, February 5, 2019

Here’s how to set up a MySQL server with a specific version using Docker.

Prerequisites

  • MySQL: Want to use version 5.7
  • OS: macOS Mojave

Starting MySQL with specific version using docker

Pulling docker image & initial startup

docker run \
--name mysql5.7 \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-p 3306:3306 \
-d mysql:5.7

Connection verification to MySQL via shell

docker exec -it mysql5.7 bash

Configuration for Docker for Mac

Connection setup query from macOS to MySQL on Docker

The important point is to execute queries for not only @“localhost” but also @”%” .

CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

CREATE USER 'myuser'@"localhost" IDENTIFIED BY "mypassword";
CREATE USER 'myuser'@"%" IDENTIFIED BY "mypassword";

GRANT all ON mydb.* TO 'myuser'@"localhost";
GRANT all ON mydb.* TO 'myuser'@"%"; # For Docker for Mac, don't forget @"%"; as well

FLUSH PRIVILEGES;

For details, please refer to MySQL ユーザのホストをワイルドカードで指定してもlocalhostは含まれない | b.l0g.jp.

That’s all from the Gemba.