1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

docker-composeで手軽にMySQLを構築する

Posted at

dockerでMySQLを構築することがよくあります。
複数必要な場合はdocker-composeを使うと便利です。

# イメージpull
# docker-compose pull
# 起動
# docker-compose up -d
# 停止/削除(ボリュームも削除)
# docker-compose down -v
# 接続
# mysql -h127.0.0.1 -P13306 -uroot -proot
# mysql -h127.0.0.1 -P23306 -uroot -proot

# 起動時に、docker-entrypoint-initdb.dにマウントしたディレクトリに存在するsqlファイルを実行してくれる

version: '3'
volumes:
    v-mysql57-db:
        driver: 'local'
    v-mysql80-db:
        driver: 'local'
services:
    mysql57-db:
        image: mysql:5.7
        container_name: mysql57_db
        environment:
            - MYSQL_ROOT_PASSWORD=root
            - TZ=Asia/Tokyo
        ports:
            - 0.0.0.0:13306:3306
        volumes:
            - v-mysql57-db:/var/lib/mysql
            - $PWD/mysql57_init.d:/docker-entrypoint-initdb.d
        command:
            - mysqld
            - --character-set-server=utf8
            - --collation-server=utf8_general_ci
            - --innodb-large-prefix=ON
            - --innodb-file-per-table=ON
            - --innodb-file-format=barracuda
    mysql80-db:
        image: mysql:8.0
        container_name: mysql80_db
        environment:
            - MYSQL_ROOT_PASSWORD=root
            - TZ=Asia/Tokyo
        ports:
            - 0.0.0.0:23306:3306
        volumes:
            - v-mysql80-db:/var/lib/mysql
            - $PWD/mysql80_init.d:/docker-entrypoint-initdb.d
        command:
            - mysqld
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_ja_0900_as_cs
            - --innodb-file-per-table=ON
            - --default-authentication-plugin=mysql_native_password
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?