도커 컴포즈를 사용한 MySQL 관리
MySQL 도커 컴포즈 설정
Section titled “MySQL 도커 컴포즈 설정”- 작업 디렉토리 생성 및 docker-compose.yaml 파일 생성
Terminal window mkdir ${WORKING_DIRECTORY}cd ${WORKING_DIRECTORY}touch docker-compose.yaml - docker-compose.yaml 파일 편집
docker-compose.yaml services:mysql:container_name: mysqlimage: mysql:latestrestart: alwaysports:- "3306:3306"environment:MYSQL_ROOT_PASSWORD: ********MYSQL_USER: ********MYSQL_PASSWORD: ********volumes:- ./db/conf.d:/etc/mysql/conf.d- ./db/data:/var/lib/mysql- ./db/initdb.d:/docker-entrypoint-initdb.d - MySQL 기동
Terminal window docker-compose up -d
MySQL 컨테이너에 연결
Section titled “MySQL 컨테이너에 연결”- MySQL 초기 설정은 도커 컨테이너에 접속해서 명령어를 입력해야 한다.
- MySQL 컨테이너의 bash 실행
Terminal window docker-compose exec mysql bash$ docker-compose exec mysql bashbash-5.1# - 관리자 권한으로 접속
Terminal window mysql -u root -p mysqlbash-5.1# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 20Server version: 9.5.0 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> - 연결 테스트
Terminal window show databases;mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.001 sec)
MySQL 데이터베이스 및 사용자 생성
Section titled “MySQL 데이터베이스 및 사용자 생성”- Database 생성
create database ${DATABASE_NAME};
- 사용자 생성
create user '${USER_NAME}'@'%' identified by '${PASSWORD}';
- 사용자 조회
select * from user where user = '${USER_NAME}';
- 권한 설정
grant all privileges on ${DATABASE_NAME}.* to '${USER_NAME}'@'%' with grant option;
- 모니터링 권한 설정
grant process on *.* to ${USER_NAME};grant select on performance_schema.* to ${USER_NAME};grant show databases on *.* to ${USER_NAME};
- 설정내역 디스크에 저장
flush privileges;
데이터베이스 활용
Section titled “데이터베이스 활용”- 외부에서 데이터베이스 작업을 수행한다.
- 테이블 및 데이터 생성
- 인덱스 생성
- 데이터베이스를 사용하는 애플리케이션 개발이 가능하다.
- 웹 애플리케이션 개발
- 모바일 애플리케이션 개발