We will summarize the procedure for building a MySQL 5.7 environment using Docker and connecting with MySQL Workbench.
Docker etc. must be installed.
Folder structure
project/
├ docker/
| └ data #Mount location
| └ db/
| ├ my.cnf #setting file
└ docker-compose.yml
** 1. Create docker-compose.yml
. ** **
version: '3'
services:
db:
image: mysql:5.7
container_name: mysql_container
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: sample_db
MYSQL_USER: mysqluser
MYSQL_PASSWORD: mysqlpass
volumes:
- ./docker/db/data:/var/lib/mysql
- ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
restart: always
ports:
- 3306:3306
** 2. Create my.cnf
(MySQL configuration file). ** **
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
[client]
default-character-set=utf8mb4
** 3. Start the MySQL container. ** **
Move to the above project
folder and execute the following docker-compose command.
docker-compose up -d
docker ps
command and check that the status of mysql_container
is UP
.** 4. Access the container from MySQL Workbench. ** **
Database
->Manage Connections ...
.The following Manage Server Connections
screen is displayed.
Press New
and enter the connection information described in docker-compose.yml
.
Check if you can connect to the container with Test Connection
.
Recommended Posts