Last active
March 21, 2024 02:31
-
-
Save rlaace423/62882e7da571302e9640aec1d2f056d1 to your computer and use it in GitHub Desktop.
mysql docker 설정 (with MacOS M1 Chip)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql -u root -p | |
# 1. user 추가 | |
create user '아이디'@'%' identified by '비밀번호'; | |
grant all privileges on DB이름.* to '아이디'@'%'; | |
또는 | |
grant select, insert, update on DB이름.* to '아이디'@'%'; | |
FLUSH PRIVILEGES; | |
# 2. user 삭제 | |
drop user '아이디'@'%'; | |
------- | |
# 권한 조회 | |
SHOW GRANTS FOR 'user'@'host'; | |
# 권한 조회 결과 - 아무것도 없는 상태 | |
# GRANT USAGE ON *.* TO `user`@`host` | |
# 계정 조회 권한 추가 | |
GRANT SELECT ON mysql.user TO 'user'@'host'; | |
# 권한 조회 결과 - 계정 조회 권한 | |
# GRANT SELECT ON `mysql`.`user` TO `user`@`host` | |
# 계정 추가/수정/삭제 권한 추가 | |
GRANT CREATE USER ON *.* TO 'user'@'host'; | |
# 권한 조회 결과 - 계정 추가/수정/삭제 권한 | |
# GRANT CREATE USER ON *.* TO `user`@`host` | |
# 계정 flush 권한 추가 | |
GRANT RELOAD ON *.* TO 'test'@'%'; | |
# 권한 조회 결과 - 계정 flush 권한 | |
# GRANT RELOAD ON *.* TO `user`@`host` | |
# 권한 제거 | |
REVOKE SELECT ON mysql.user from 'user'@'host'; | |
REVOKE CREATE USER ON *.* from 'user'@'host'; | |
# 사용 가능한 비밀번호 플러그인 목록 | |
SELECT PLUGIN_NAME FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_TYPE = 'AUTHENTICATION'; | |
# 비밀번호 변경 (v8) | |
ALTER USER 'test'@'%' IDENTIFIED WITH caching_sha2_password BY 'test'; | |
# 비밀번호 변경 (v5.7) | |
ALTER USER 'user'@'host' IDENTIFIED WITH sha256_password BY 'RANDOM_PASSWORD'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.9" | |
services: | |
mysql: | |
image: arm64v8/mysql:8.1 # 이미지 버전 확인 필요! | |
restart: always | |
container_name: mysql | |
ports: | |
- "3306:3306" | |
networks: | |
- mysql | |
environment: | |
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password | |
volumes: | |
- type: bind | |
source: $HOME/mysql/data | |
target: /var/lib/mysql | |
- type: bind | |
source: $HOME/mysql/my.cnf | |
target: /etc/my.cnf | |
secrets: | |
- mysql_root_password | |
networks: | |
mysql: | |
name: mysql | |
driver: bridge | |
secrets: | |
mysql_root_password: | |
file: .mysql_root_password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. docker 설치 (https://docs.docker.com/engine/install/ubuntu/) | |
# 2. mysql image 다운로드 | |
docker pull mysql | |
# 3. data, my.cnf 가 마운트 될 위치 생성 | |
#### data 디렉토리 생성 | |
~/mysql/data | |
#### my.cnf 생성 (내려받은 image가 기본으로 생성하는 my.cnf를 가져오는게 안전함!) | |
~/mysql/my.cnf | |
(아래의 my.cnf 참고) | |
# 4. docker-compose.yml 작성 | |
(아래의 docker-compose.yml 참고) | |
# 5. mysql container 띄우기 | |
docker-compose up -d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; version 2 of the License. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
# | |
# The MySQL Server configuration file. | |
# | |
# For explanations see | |
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html | |
# Custom config should go here | |
!includedir /etc/mysql/conf.d/ | |
[mysqld] | |
pid-file = /var/run/mysqld/mysqld.pid | |
socket = /var/run/mysqld/mysqld.sock | |
datadir = /var/lib/mysql | |
secure-file-priv= NULL | |
# Allow remote access (Sangho Kim, 2021-12-28) | |
bind-address = 0.0.0.0 | |
# Set utf8mb4 (Sangho Kim, 2021-12-28) | |
character-set-server=utf8mb4 | |
collation-server=utf8mb4_unicode_ci | |
skip-character-set-client-handshake |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment