0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docker テーブル作成

Last updated at Posted at 2025-04-27

MysqlにDockerでTableを作成

かなり時間を割いたので、備忘録として記載

まず、Docker DesctopでMysqlデータベースは作成済み
問題は、そのデーターベースにテーブルを作成する工程でつまづいた

まずは、現在のymlファイルの定義

services:
  db:
    image: mysql:8
    container_name: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${ROOT_PASS}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      TZ: ${TZ}
    ports:
        - ${DB_PORT}:3306
    volumes:
        - db-store:/var/lib/mysql
        - ./conf/my.cnf:/etc/mysql/conf.d/my.cnf
        - ./docker/initdb:/docker-entrypoint-initdb.d
volumes:
  db-store:
  • ./docker/initdb:/docker-entrypoint-initdb.d

このファイルのディレクトリが理解できず、無駄に時間を食ってしまった。

C:\Users<ユーザー名>\mysql
ここにymlファイルがあるので、それを上記に編集

その後
 - ./docker/initdb:/docker-entrypoint-initdb.d- に以下、SQL文を配置

CREATE TABLE test.employee (	
	id int,
	name varchar(10)
);

で、dockerを起動してテーブルが作成されていることを確認
image.png

問題なし!

来週は、テーブルの設計、データベースへのアクセス&取得したデータの表示までを目標に

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?