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】mysql学習用環境をローカルに爆速で構築する

Last updated at Posted at 2021-03-17

はじめに

MYSQLを学習するための環境をdockerで構築する。
データを自前で用意するのは非常に面倒だが、公式で
サンプルデータとして、worldデータベースが提供されているので
そのデータを使用してデータベースを構築する。

環境構築

以下のファイルを作成

Dockerfile
FROM mysql:5.7

RUN apt-get update && apt-get install -y \
    curl unzip

RUN curl -OL https://downloads.mysql.com/docs/world-db.zip

RUN unzip world-db.zip

RUN mv world-db/world.sql docker-entrypoint-initdb.d/world.sql 
docker-compose.yml
version: '2'
services:
  mysql:
    build: .
    tty: true
    working_dir: /mnt
    volumes:
      - ./:/mnt/
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test

起動コマンド(~コンテナログイン)

docker-compose up -d
docker-compose exec mysql bash

mysqlログイン~テーブル確認


mysql -uroot -proot
use world;
select * from city;

以下のように出力されていれば構築完了です。

+------+-----------------------------------+-------------+----------------------+------------+
| ID   | Name                              | CountryCode | District             | Population |
+------+-----------------------------------+-------------+----------------------+------------+
|    1 | Kabul                             | AFG         | Kabol                |    1780000 |
|    2 | Qandahar                          | AFG         | Qandahar             |     237500 |
|    3 | Herat                             | AFG         | Herat                |     186800 |
|    4 | Mazar-e-Sharif                    | AFG         | Balkh                |     127800 |
|    5 | Amsterdam                         | NLD         | Noord-Holland        |     731200 |
|    6 | Rotterdam                         | NLD         | Zuid-Holland         |     593321 |
|    7 | Haag                              | NLD         | Zuid-Holland         |     440900 |

最後に

mysqlを学習するための環境をdockerを用いて構築してみました。
わからないことなどあれば気軽にコメントお願いいたします。

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?