사이트 참고 :hub.docker.com/_/mysql/

 

mysql

We and third parties use cookies or similar technologies ("Cookies") as described below to collect and process personal data, such as your IP address or browser information. You can learn more about how this site uses Cookies by reading our privacy policy

hub.docker.com

사전 준비사항 : docker 설치 상태

MySQL Image Download

$ docker pull mysql

# 또는 버전을 명시
$ docker pull mysql:8.0.23

# 둘다 해봄 1번 4번
$ docker images
 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0.23              26d0ac143221        2 days ago          546MB
mysql               latest              26d0ac143221        2 days ago          546MB

Log

Using default tag: latest
latest: Pulling from library/mysql
6f28985ad184: Pull complete 
e7cd18945cf6: Pull complete 
ee91068b9313: Pull complete 
b4efa1a4f93b: Pull complete 
f220edfa5893: Pull complete 
74a27d3460f8: Pull complete 
2e11e23b7542: Pull complete 
fbce32c99761: Pull complete 
08545fb3966f: Pull complete 
5b9c076841dc: Pull complete 
ef8b369352ae: Pull complete 
ebd210f0917d: Pull complete 
Digest: sha256:5d1d733f32c28d47061e9d5c2b1fb49b4628c4432901632a70019ec950eda491
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

 

 

Docker MySQL 컨테이너 생성 및 실행

  • -V 옵션을 통하여 호스트 경로를 컨테이너의 경로로 마운트 할수 있다고 한다.
    • ex) -v /Mydir:/컨테이너디렉토리
  • 컨테이너 삭제시 데이터도 함께 지워진다고하니 저장소는 외부저장소를 지정하여 사용하도록 한다.
$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password --name sqlserver -v /SERVER/mysql/data:/var/lib/mysql mysql:8.0.23 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
3fd45a85dd76590d2e61c40bf1a90e2f8f2677385304923e7c742a6d03027311

# Docker 컨테이너 목록보기
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                               NAMES
3fd45a85dd76        mysql:8.0.23        "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, 33060/tcp   sqlserver

 

 

MySQL 컨테이너 bash 쉘 접속

docker exec -it sqlserver bash

root@3fd45a85dd76:/#
$ mysql -u root -p
Enter password: 패스워드 입력
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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> 

 

 

'Database' 카테고리의 다른 글

[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19

+ Recent posts