2
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簡易構築

Last updated at Posted at 2021-05-01

MySQLに接続してみよう

image.png

材料

  • さくらVPS
  • docker-compose
  • MySQL公式サンプルデータベース
  • teraterm

準備

mysql-test/
   + docker-compose.yml
   + conf.d/
   + data/
   + docker-entrypoint-initdb.d/
        + world.sql.gz
docker-compose.yml
# vim: set ts=2 et:
version: '3.1'

services:

  db:
    image: mysql:8.0.24
    volumes:
      - ./data:/var/lib/mysql
      - ./conf.d:/etc/mysql/conf.d
      - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
    command: --default-authentication-plugin=mysql_native_password
    cap_add:
      - SYS_NICE
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: my-secret-pw
      MYSQL_DATABASE: world
      MYSQL_USER: user1
      MYSQL_PASSWORD: pass1

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOSTS=db
      - PMA_USER=root
      - PMA_PASSWORD=my-secret-pw
    ports:
      - 10080:80
$ wget https://downloads.mysql.com/docs/world.sql.gz
$ mv world.sql.gz docker-entrypoint-initdb.d/
  • TeraTermでポートフォワード設定
    image.png

起動&確認

docker-compose up  // or start

http://localhost:10080 でブラウザアクセスするとphpmyadminが起動

image.png

なお、PyCharmであればSSHトンネルの使用という機能でTeraTermでのSSHポートフォワードの設定の代わりができる(Professional版)
image.png

dockerのmysql8環境でmbind: Operation not permitted
【SQL】MySQL公式サンプルデータベースを使う - Qiita
TeraTerm SSH転送(ポートフォワード)機能よりローカルIPアドレスでphpmyadminログイン - 協栄情報ブログ
PyCharmでSSHトンネル経由でDBに接続する - Qiita

2
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
2
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?