LoginSignup
2
3

More than 1 year has passed since last update.

dockerでmysql8.0を利用する最小確認構成

Posted at

概要

フォルダ構成

.
├─docker-compose.yml
└─mysql
   └─conf.d
      └─mysql.cnf

ファイル

docker-compose.yml
version: '3.8'
services:
  db:
    image: mysql:8.0
    ports:
      - '3306:3306'
    volumes:
      - ./mysql/conf.d:/etc/mysql/conf.d
      - mysql:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
      TZ: "Asia/Tokyo"
volumes:
  mysql:
mysql/conf.d/mysql.cnf
[mysqld]
default_authentication_plugin = mysql_native_password
skip-host-cache
skip-name-resolve

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect = SET NAMES utf8mb4
skip-character-set-client-handshake

[client]
default-character-set = utf8mb4

[mysqldump]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

コマンド

コンテナ起動

docker-compose up -d

mysql接続

docker-compose run db mysql -h db -u root

結果

# mysql -h db -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

以上

railsなどから接続する際にはdatabase.ymlにてhost: dbとしてやる

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3