간략한 절차
0.도커 설치 및 docker hub 로그인 (생략)
도커 mysql을 설치하여 컨테이너로 돌리는 방법은 2가지가있다.
첫째로 docker image를 다운받고, 'docker run image' 하여 돌리는것과
docker-compose.yml 파일을 작성하여 docker-compose up 을 하는것..
두가지방법이다.
docker mysql image 다운
docker pull mysql:8

mysql 이미지가 만들어졌다. 이 mysql 이미지로 docker-compose를 작성하겠다.
docker-compose.yml 작성
version: "3"
services:
mysql:
image: mysql:8
restart: always
environment:
MYSQL_DATABASE: "데이터베이스명"
MYSQL_ROOT_PASSWORD: "패스워드"
MYSQL_ROOT_HOST: '%'
ports:
- "3306:3306"
docker-compose up -d 명령어를 이용하여 container를 동시킨다.
container로 진입
ubuntu:~$ docker exec -it 'containerID' /bin/bash
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 8.1.0 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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 설정하기
# 데이터베이스 추가
create database 데이터베이스명;
# User 추가 및 권한 부여
create user 'user명'@'%' identified by '비밀번호';
grant all privileges on 데이터베이스명.*TO 'user명'@'%';
flush privileges;
※ docker 컨테이너 주요 명령어
# MySQL Docker 컨테이너 중지
$ docker stop containerID
# MySQL Docker 컨테이너 시작
$ docker start containerID
# MySQL Docker 컨테이너 재시작
$ docker restart containerID
# Mysql Docker 컨테이너 삭제
$ docker rm containerID
'잡다한' 카테고리의 다른 글
SpringBoot에 Swagger3 설정하기(Gradle) (0) | 2023.07.06 |
---|---|
H2 인메모리DB 세팅 (0) | 2023.07.02 |