1. MySQL 컨테이너 접속
1) MySQL 컨테이너 접속
- Windows PowerShell
PS C:\Users\admin> docker run -e MYSQL_ROOT_PASSWORD=pwd123 -p 3306:3306 -d mysql
e092551c6f7622487c662f587822d8ea85e7796c97e37c85286eb815b5d075e3
PS C:\Users\admin> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e092551c6f76 mysql "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp gracious_haibt
PS C:\Users\admin> docker exec -it e092 bash
bash-5.1# ls
afs bin boot dev docker-entrypoint-initdb.d etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
2) 컨테이너에서 MySQL에 접근
- Windows PowerShell
bash-5.1# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 9.7.0 MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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> help
For information about MySQL products and services, visit:
https://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
https://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command, if enabled
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.
ssl_session_data_print Serializes the current SSL session data to stdout or file
For server side help, type 'help contents
3) 데이터베이스 조회
- Windows PowerShell
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.003 sec)
4) 데이터베이스 만들기
- Windows PowerShell
mysql> create database mydb;
Query OK, 1 row affected (0.012 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.000 sec)
mysql> exit
Bye
bash-5.1# exit
exit
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug e092
Learn more at https://docs.docker.com/go/debug-cli/
5) 컨테이너 종료 후 다시 생성
- Windows PowerShell
# 컨테이너 종료
PS C:\Users\admin> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e092551c6f76 mysql "docker-entrypoint.s…" 5 minutes ago Up 4 minutes 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp gracious_haibt
PS C:\Users\admin> docker stop e092
e092
PS C:\Users\admin> docker rm e092
e092
# 컨테이너 생성
PS C:\Users\admin> docker run -e MYSQL_ROOT_PASSWORD=pwd123 -p 3306:3306 -d mysql
2d4873b9ad9c31520392b1090f38899094002faba779277ca8d38c21869d0283
PS C:\Users\admin> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d4873b9ad9c mysql "docker-entrypoint.s…" 13 seconds ago Up 13 seconds 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp confident_ptolemy
# 컨테이너 접근
PS C:\Users\admin> docker exec -it 2d48 bash
# MySQL 접근
bash-5.1# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 9.7.0 MySQL Community Server - GPL
Copyright (c) 2000, 2026, 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> show databases; # 아까 생성한 데이터베이스가 없어진 걸 확인할 수 있다.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.002 sec)
MySQL 컨테이너를 삭제함과 동시에 MySQL 내부에 저장된 데이터도 함께 삭제되었다.
이를 방지하기 위해 볼륨(Volume)을 활용해 MySQL 컨테이너를 띄워야 한다.
참고링크 : https://www.inflearn.com/course/%EB%B9%84%EC%A0%84%EA%B3%B5%EC%9E%90-docker-%EC%9E%85%EB%AC%B8-%EC%8B%A4%EC%A0%84?cid=334085
비전공자도 이해할 수 있는 Docker 입문/실전| JSCODE 박재성 - 인프런 강의
현재 평점 4.9점 수강생 14,449명인 강의를 만나보세요. 비전공자 입장에서도 쉽게 이해할 수 있고, 실전에서 바로 적용 가능한 Docker 입문/실전 강의를 만들어봤습니다! Docker 기본 개념, Spring Boot를
www.inflearn.com
'강의 실습 > 비전공자도 이해할 수 있는 Docker 입문 실전' 카테고리의 다른 글
| [실습] Docker로 MySQL 실행시켜보기 - 4 (0) | 2026.05.09 |
|---|---|
| [실습] Docker로 MySQL 실행시켜보기 - 3 (0) | 2026.05.09 |
| [실습] Docker로 MySQL 실행시켜보기 - 1 (0) | 2026.05.08 |
| [보충 자료] Windows에서 lsof, kill, sudo 명령어가 작동하지 않을 때 대처 방법 (0) | 2026.05.06 |
| Docker Volume(도커 볼륨) (0) | 2026.05.06 |
댓글